Search code examples
c++stringcharfltk

Issues with FLTK and concatenated char


I working on FLTK application (C++) and I have to create names to set in a Fl_Browser. Basically this structure receive a "const char*" with

browser->add("my string..");

but... I need that each string receive the correct name: "Process" plus the it number, like: "Process 1", "Process 2", ...

the entire string must be a const char*, the number is receive by a counter, which is increased by a while command;

I need something like this:

int count=1;
while (count < 100) {
    const char* name;
    name = "Process" + count;        
    count++;
}

How can I concat this two variables?


Solution

  • You should use a string stream, like this:

    while (count < 100) {
        std::ostringstream name;  
        name << "Process" << count;
        browser->add(name.str().c_str());
        count++;
    }