Hello everyone,
I don't know if I'm confused with itoa,excuse me for this if so, but what I'm trying to do is:
I have an array of characters, say

char example[7]

I assigned the first 4 characters by

strcpy(example,"Fill");

Then I'm trying to fill the next char with an integer using itoa:

example[4]=itoa(i,example[4],10);

where i is an incremental integer variable in a for loop.
the rest of the char array is constant.
example[5]='x';
example[6]='\0';
Thank you for your replies.
Cheers,

Recommended Answers

All 4 Replies

This is an ideal situation which which to use stringstreams. Are you locked into using the characters array?

Also, itoa is non-standard so it's not guaranteed to be available on all compilers.

Hello jonsca,
Well, I could switch to a string,doesn't matter at all,if only I knew how to use stringstreams :) :(

It's relatively easy:

#include <sstream>
//...
int numbervariable = 10; //or double, etc. or use your loop counter
std::stringstream ss;
ss<<"Firstpart"<<numbervariable<<"Secondpart"; //use it just like any other stream

std::cout<<ss.str()<<" is the string portion";

Thank you Jonsca.Appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.