the reason it only writes the first part is because you are using cin. try getline instead. As far as the writing goes what are you trying to do? Write over the existing name , score, and date? or Append it to a new line?
I would like to make it export what ever is imputed, for example,
lets say I have two things,
then I set them,
score = 11;
name = Winner;
I want to get here;
43 Ronnie //old score
92 Abby //old score
11 Winner //new score // I want to put it down a line from the last one.
In the future, I may want to organize it by high scores, but that seems a bit to complicated right now, what do you think?
P.S. I am not in a actual C++ class, I am in an independent study class where I can learn anything I want, and I chose to learn C++. So none of this is homework, I just want to learn these things... If you have any learning Advice(for C++), I would greatly appreciate anything.
#include <iostream> //std::endl
#include <fstream> //std::ofstream
int score( 999 );
std::string name( "Giblit" );
std::ofstream out( "output.txt" );
out << score << " " << name << std::endl;
out.close(); //I don't think this is really necessary most compilers close the file automatically when done with it
return( 0 );
You were just missing the new line after the output =p
I see a lot of people not using "using namespace std;", instead, they are
adding std:: , whats the difference? and what shoudl I be doing?
Your program is simple, although, it has the same problem as my program has; It over writes the textfile.
I have thought about learning how to read a text file, and then store the information in the text file, into the program, so it would be saved as, old stuff in the text file + new stuff I want to save with the old stuff.
Is this teh only way? there must benother way.
Oh whoops forgot to put the append change line 8 to
1 2 3 4 5 6
std::ofstream out( "output.txt" | ios::app );
std::ofstream out( "output.txt" , ios::out | ios::app );
/**Forgot which one works but one of them should**/
//ios::app means to append to end of file
//This website should have a basic i/o with files section