bennyandthejets is right. The integer (created by a random number generator) is "50", to be written to a text file as
"50"--in readable form.
bennyandthejets is right. The integer (created by a random number generator) is "50", to be written to a text file as
"50"--in readable form.
Deum solum fidentia est
Why all the confusion?
Code:#include <iostream> #include <fstream> #include <cstdlib> using namespace std; int main(void) { ofstream f; int i; srand (10); // Amend as appropriate f.open ("out.txt"); if (f) { i = rand() % 10; f <<i <<flush; f.close(); } else cerr <<"open error" <<endl; return(0); }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Hammer, is the file "out.txt" an ASCII file that one can read, or is it a binary?
The file that I need must be ascii, like an ini file.
THX
Deum solum fidentia est
ripper079 is very correct. You can also useCode:int main() { int number = 50; char buffer[10]; /* itoa(the number, the buffer for the return string, the base of the number); */ itoa(number, buffer, 10); //do stuff with buffer return 0; }
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
The file out.txt is in text format (ascii char's), so you should be fine.Originally posted by deleeuw
Hammer, is the file "out.txt" an ASCII file that one can read, or is it a binary?
The file that I need must be ascii, like an ini file.
THX
Thanx all!
the itoa ([int], [char], 10) worked!
Deum solum fidentia est