After I create a random text file called text.txt with
Code:
std::fstream fin, fout;
fout.open("c:\text.txt", std:ios::out); //ignore the smily its an ':'':'o';
if(!fout.is_open()) return 0;
//I wrote 10 lines of strings to the file with:
while (int i = 0; i <= 10; i++) {
fout << "This is line #" << i++ << std::endl;
fout.close();
//now I open the file to get the string of characters for each line
//and print them to the screen
fin.open("c:\text.txt", std::ios::in);
if(!fin.is_open()) return 0;
std::string str;
while (!fin.eof()) {
std::getline(fin, str, '\n'); //why is it FN? and '\n' for params???
std::cout << str << std::endl; //prints str line.
fin.close(); //close fstream.
system ("PAUSE");
}
My question is, if I create a text file manually - and simply want to get the lines of strings in the file how do I go about this? Simply use fin.open("c:\text.txt", std::ios::in);? and then instantiate a string to retrieve all data untill the end of the file? ::
::EDIT:: - also why do I need to use standard before each operator? i.e. std::cout, std::string str?