reading files line by line
Hey all,
i want to make a script that doesn't only open a file and write the content, but that can also write specific lines to variables
1 2 3 4 5
|
hello
this
is
my
script
|
I want the script to read line 5
how do i do that?
How can i tell the script to read a specific line?
Try clarifying your problem, you speak of writing a line but you want your script to "read" a line.
First of all, what should be passed to your "script"? (const char*, char* or std::string)
Second, what is your script in the first place?
For a full explanation of File I/O, check the following link:
http://www.cplusplus.com/doc/tutorial/files/
I will usually just load the file into a
deque <string>
, and then mess with it.
1 2 3 4 5 6 7
|
std::istream& operator >> ( std::istream& ins, std::deque <std::string> & lines )
{
std::string line;
while (std::getline( ins, line ))
lines.push_back( line );
return ins;
}
|
1 2 3 4
|
deque <string> script;
ifstream f( ... );
f >> script;
f.close();
|
Good luck!
Topic archived. No new replies allowed.