c++ help...

EngenZerO

Diamond Member
Dec 24, 2001
5,099
2
0
Hey I have a quick question..

how can one take a specific integer and add it to a set of characters. This needs to be an specific item. I just cant use sprintf/printf.

ex. taking 1 and xx to produce -> 1xx.
 

BFG10K

Lifer
Aug 14, 2000
22,709
3,003
126
Do you need to store it or just print it? If you need to store it you could use an output string stream.
 

EngenZerO

Diamond Member
Dec 24, 2001
5,099
2
0
store it as a variable so that another program can read it..... we are learning about shared memory.

right now I am attempted to mess with this iota command.
 

singh

Golden Member
Jul 5, 2001
1,449
0
0
Here's one way:

#include <sstream>
using namespace std;

.... Assume integer has the number. The string 'combined' will have the result ....


ostringstream oss; oss << integer;

string combined = oss.str() + "xxx";

 

TerryMathews

Lifer
Oct 9, 1999
11,464
2
0
It's been awhile, but try something like this.

int num = 1;
string word = "fineday";
string sentence = (string)num + word;
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Even though you stated your can not use sprintf, there must be another reason

string_buffer;
sprintf(string_buf,%d%s",int_var,string_var);

or

string string_buffer;
string_buffer = itoa(int var) + string_var;