I am new to c++ and have a (curious) problem while writing a file using the ofstream class. I am working on Monte Carlo simulation but my problem only concerns writing numbers in file. Indeed I have no problem for writing text in a file but I can't do anything with numbers (without having an error while compiling). Here is my code :
ofstream outf;
outf.open("test.txt");
outf << "The number is: " << Nb << endl;
outf.close();
return 0;
}
When I do that, I just have "The number is:" written in my file. So I first thought the ofstream class didn't allow to write two "expressions" in one command line, so I wrote the next file:
ofstream outf;
outf.open("test.txt");
outf << Nb << endl;
outf.close();
return 0;
}
And I have absolutely nothing in my file!!! Simply great! So I don't really understand where the problem is. Could anyone help me? Please!! One thing that might be useful to know is that I use Xcode to code (with a native GNU/GCC compiler).