I have a text file like this:
1 2 3
4
5 6 7 8
just with money we can live
2 5
with this piece of code, I can show whole it on screen, but I cannot put it in a string, and its compile gives error :
string test ="";
string line2;
freopen("a.txt", "rb", stdin);
while(getline(cin, line2)) {
cout << line2 << endl;
line2 >> test;
}
1- Is it possible to put whole of text file in "test"?
2- and instead of using something like this :
string test =
"1 2 3"
"4"
"5 6 7 8"
"just with money we can live"
"2 5";
is it possible to use a loop and freopen or something like these?
I read this "Read file line by line using ifstream in C++", but it is for identical number of column.
If there is a website to answer my question, please give it to me.