Convert int to str bug.

I'm trying to write an incrementing number into a tab deliminated text file. I googled some methods and compiled until there were no errors. It works nearly perfectly the way I want it. Except output of 'numOut' is like this:
"...1" (10x)
"...01" (10x)

When in fact I want #'s 1-20 printed. I'm clueless as to what I did wrong,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const char* numOut;
string tempstring;
fstream d2mod;
stringstream out;

int length, filebuffer; //maybe used later for reading the file

main()
{
d2mod.open("magicprefix.txt");
d2mod.seekg(0, ios::end);//goto eof

	for(int x=0;x<20;++x)
	{
		int buffersize;
			if(x<10){buffersize=1;};
			if(x>=10){buffersize=2;};

        out << x;
        tempstring=out.str();//write x into tempstring
        numOut=tempstring.c_str();//write string into char

		d2mod.write("Strong",6);//name
		d2mod.write("\t", 1);
		d2mod.write("100",3);//version
		d2mod.write("\t", 1);
		d2mod.write("1",1);//rare
		d2mod.write("\t", 1);
		d2mod.write("", 0);//level
		d2mod.write("\t", 1);
		d2mod.write("", 0);//maxlevel
		d2mod.write("\t", 1);
		d2mod.write("", 0);//levelreq
		d2mod.write("\t", 1);
		d2mod.write("", 0);//class spec
		d2mod.write("\t", 1);
		d2mod.write("", 0);//what class?
		d2mod.write("\t", 1);
		d2mod.write("", 0);//freq
		d2mod.write("\t", 1);
		d2mod.write("", 0);//group
		d2mod.write("\t", 1);
		d2mod.write("str",3);//mod1code
		d2mod.write("\t", 1);
		d2mod.write("", 0);//mod1 par
		d2mod.write("\t", 1);
		d2mod.write(numOut ,buffersize);//mod1 min
		d2mod.write("\t", 1);
		d2mod.write(numOut ,buffersize);//mod1 max 
Wouldn't it have been easier to do d2mod <<"strong\t100\t1\t\t\t\t\t\t\t\tstr\t\t"<<numOut<<"\t"<<numOut;?
Last edited on
You're right, that is much easier. I'm not familiar with "<<" yet.

Side note, replace-all saves me soooooooo much work.
Topic archived. No new replies allowed.