Im trying to read a textfile and output everything line by line to konsole. but rather every word encountered results in a new line. How would i go about to getting line by line done in the console rather a new line for every word space?
#include <iostream> // for console I/O
#include <fstream> // for file I/O
#include <string> // almost forgot this, you need this for getline
usingnamespace std;
int main()
{
string szInput; // going to store the input in a string
ifstream fin; // creating an object of ifstream
fin.open(/*file name*/); // open the file
if (!fin.is_open())
return 1; // return error if the file isn't opened
while(!fin.eof()) // loop until the end of the file
{
getline (fin, szInput, '\n'); // get a line of characters until a newline character is found
cout << szInput << endl; // display input, end line
}
cin.get(); // so you can see the results
fin.close(); // close the file
return 0; // self explanatory
}
I'll be honest, haven't tested it, but I'm confident it works.