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];
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
Code:#if _emo #define stereo_type_i_dislike #endif
where/can you specify what line you want?
Last edited by Okiesmokie; 03-01-2002 at 08:11 PM.
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. }
Tazar The Demon
-------------------------------------
Please check my site out at: http://www.lrs.8m.com thanks =)
-------------------------------------
Note:
I will help newbies and any other person that I can just ask I'll try to help you out =)
My MSN Messager name is: [email protected] see if I'm online maybe we can talk. =)