I have 2 questions:
I am trying to take input from another file, initialize them into variables, then output the variables to another file. I am able to get all input into separate variables except for 1 line (the line should be a variable).
My input file contains this data:
557.9012043 0.673621489 7210984732 1.891092837
238 a 789.234 b
Yes Please
cannot wait for hawaii
The line "Yes Please" should be taken as a whole string, however, "Yes" and "Please" are getting separated.
My code for this is:
outFile << fixed << showpoint;
outFile << setprecision(10);
inFile >> w >> x >> y >> z >> int1 >> char1 >> float1 >> char2 >> string1
>> word1 >> word2 >> word3 >> word4;
outFile << w << endl;
outFile << x << endl;
outFile << y << endl;
outFile << z << endl;
outFile << float1 << endl;
outFile << int1 << endl;
outFile << char1 << endl;
outFile << char2 << endl;
outFile << string1 <<endl;
outFile << word1 << endl;
outFile << word2 << endl;
outFile << word3 << endl;
ouFile << word4 << endl;
}
When I run it, my outFile consists of:
557.9012043000
0.6736214890
7210984732.0000000000
1.8910928370
789.2340000000
238
a
b
Yes
Please
cannot
wait
for
How can I get the whole line, "Yes Please" assigned to my variable string1?
Question 2: My outFile has all of the extra 0's in the floating point variables because I set the precision. My goal, really, is to use the variables to solve equations. I would like the answers to the equations to only print 10 significant digits. How would I accomplish this task without the precision after the decimal being 10 digits?
I am very new to C++, so when if you answer, can you please explain why you gave the answer you did. I'm not trying to only receive answers, I want to learn. Thank you.