tags:

views:

103

answers:

4

Possible Duplicate:
C++ concatenate string and int

Hi,

In C# I can write like this:

int i = 0;
string text = "out.jpg";
while(true)
{
     i++;
     Object.write(i+text, stream);
}

But this is not true for C++. the problem is at: i + default.

How could I fix this in C++?

Thanks in advance. Your help is much appreciated!

+1  A: 

default is a keyword in C++. You can't have string default in C++. And I don't see what you are trying to achieve. Please clarify

Armen Tsirunyan
+1  A: 

take a look at stringstreams or boost.format http://www.boost.org/doc/libs/1_38_0/libs/format/doc/format.html

boost::format("%1%%2%") % i % default_;
DaVinci
+2  A: 

You could use a stringstream...

std::stringstream ss;
ss << i << text;
Object.write(ss.str(), stream);
cHao
+1. First I thought about `sprintf()`, but this is not really a C++ solution, rather a C one and it requires some usage of a `char` array. Using `stringstream` is probably the best solution.
rhino
A: 

default is a reserved keyword. Change the variable name to defaultStr or similar, and everything should work fine.

Olie