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.
Printable View
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.
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);
}
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
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;
}
The file out.txt is in text format (ascii char's), so you should be fine.Quote:
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!