while(inputFileStream >> one >> two >> three >> four >> five >> six)
//ASSUMING THERE ARE LESS THEN 6 STRINGS PER LINE
{
outputFileStream << four << " " << one << endl;
};
Sample Rank.txt file:
1 fruit ranked Apples comment junk
2 fruit ranked Oranges
3 fruit ranked Blue Berries comment junk
4 fruit unranked Bananas
Hello everyone. I have a question regarding reading lines from file.
The main question is, Is there a way to stop reading a line mid way(or whenever you choose) and go to the next line?
So in my above code, is there a way that i could stop reading at four and go to the next line and keep doing so until eof? I don't know if there is a type of endline or endofline marker that i can put.
To read from files you need to #include <fstream>
And after that, you do this for an example:
std::ifstream readData;
std::ofstream writeData;
readData.open("file.txt");
If(readData.fail())
{
perror("file.txt");
}
std::string lines [100];
for(int j = 0; 0 < 100; i++)
{
std::getline(readData, lines[i],'\n');
}
That should get you to understand the basics.
If it's not enough, search in Google: C++ input and output with files.
There is a guide in this site about it.
Good luck!