How do i get one line of a text file and turn it into a string?
Using fstream.h
IE. Get line 2 and make it char line2[100];
Printable View
How do i get one line of a text file and turn it into a string?
Using fstream.h
IE. Get line 2 and make it char line2[100];
Heh ;something i actually know:
#include <iostream.h>
#include <fstream.h>
char line[100];
int main()
{
ifstream intput('whatever.txt");
input>>line;
cout<<line;
input.close();
return 0;
}
hehehe
where/can you specify what line you want?
Ok using fstream.h I would just loop throu all the lines you don't want and then grab the one you want like this:
Hope that helps ^_^Code:#include <fstream.h>
#include <iostream.h>
#define LINE_NUMBER 2
int main()
{
ifstream i; //Main file object.
char buff[100]; //Input buffer.
i.open("whatever.txt"); //Open file.
//Go throu all line tells the right one.
for(int count=0;count<LINE_NUMBER;count++)
{
i.getline(buff,100); //Get line.
}
cout<<"Line "<<LINE_NUMBER<<" in the file was the data: "<<buff<<endl; //Tell user results.
i.close(); //Close file.
return 0; //Done.
}