Hello everyone,i have this following code where i read from a txt file and i pass each of the 3 first lines into three integers.The fourth line is txt,i try to pass the fourth into i string but i can't.Then i try it to pass in a array but it reads until the first space.
What should i do i order to read the hole fourth line?
#include<fstream>
#include<iostream>
usingnamespace std;
int main()
{
ifstream inStream,inStream2;
ofstream outStream;
inStream.open("infile.txt");
outStream.open("outline.txt");
int first,second,third;
char str[20]; //Here is my concern
inStream>>first>>second>>third>>str;
outStream<<"The sum of the numbers \n"
<<"in infile.txt \n"
<<"is:"<<(first+second+third)
<<" and the text:"
<<str<<endl;
inStream.close();
outStream.close();
cin.get();
return 0;
}
//...
int first,second,third;
string str;
inStream>>first>>second>>third;
inStream.get(); //get rid of the
//newline character
getline(inStream,str);
//...