The below code simply reads the string "This is a test" from a text file and displayes it on the console.
I've deliberately placed an endline at the end of each time the string is loaded to show that the string is all that is passed to 'mystring' from 'myfile'.
Is there a way in C++ to increase the number of characters picked up by 'myfile' ? Say, for the first loop of while instead of 'myfile' only picking up "This", it picks up "This i" and on the next loop it picks up the next 6 characters including white space "s a te" etc?
At the moment, 'myfile' only takes in everything up to the first white space.
Thanks
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream myfile;
string mystring;
myfile.open("myfile.txt");
while (!myfile.eof())
{
myfile>>mystring;
cout << mystring << endl;
}
myfile.close();
}