Input using the >> operator is delimited by whitespace, so by default you'll only read the next "word" in the stream. If you want a full line, use getline().
deceptikon
Challenge Accepted
3,499 posts since Jan 2012
Reputation Points: 822
Solved Threads: 481
Skill Endorsements: 58
Here's a quick example:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string filename;
ifstream fin(filename.c_str(), ios::in);
if (fin.is_open()){
string line;
while (getline(fin, line)){
cout<<line;
}
}
else cout<<"Invaild file.";
return (0);
}
Getline will take the input from the file either till '\n' appears or the EOF (end of file).
So, you put it in a while loop, and you get the output.
You can add delimiters, but here's not the case.
Here's a usefull link about getline.
Lucaci Andrew
Practically a Master Poster
690 posts since Jan 2012
Reputation Points: 108
Solved Threads: 97
Skill Endorsements: 13
Question Answered as of 11 Months Ago by
deceptikon
and
Lucaci Andrew