• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

getting a file one line at a time.

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

cack01

Member
Joined
Mar 7, 2002
Location
San diego or UC Davis
Im using C++, and I need to get into a file and take one line at a time, and store that line so I can filter through it.

I am able to do it one character at a time, but I'm having problems doing it with the whole line.

Any help is welcome.

thanks,
cack01
 
OP
cack01

cack01

Member
Joined
Mar 7, 2002
Location
San diego or UC Davis
Got it, took me a while but I figured it out. Now if only I can figure out how to use stktok(). :D

#include <iostream>

using std::cout;
using std::endl;
using std::ios;

#include <fstream>

using std::ifstream;


int main ()
{
char baby[1024];
ifstream infile;

infile.open( "Listings2.csv", ios::in);
while(infile)
{
infile.getline(baby,1024);
cout<<baby<<endl;
}



return 0;
}
 

naif

Member
Joined
Feb 17, 2002
strtok() prototype :- char *strtok(char *s1, const char *s2);

s1 is the variable which you want to scan through, s2 is the variable which holds the string to scan. It points at the beginning of the start of the string s2 in the string s1. Example usage would be

char name[] = "Overclockers Forum, Programming Section";
char *ptr;

ptr = (name,"Forum");

Now, the first letter ptr would be pointing to would be to the letter F
:cool: