Question: Is there an easy way to append an integer to a string?

I have a for loop like this:

```
for (int i = 0; i < text.length(); i++) {
  for (int g = 0; g < word.length(); g++) {
    if (text[i] == word[g]) {
      kodas.append(g);
    }
  }
}

```

and I need to get the index of the array which is equal, and the index of course is an integer type. But as I do this I get an error:

```
invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]|

```

is there a way to fix this?

Answer: 
**Yes**.

You can, for example:

* use the `itoa` function that converts integers into strings
* make your `kodas` an `ostringstream` and "write" into it as you would to `cout`: `kodas << g`
There are several ways of formatting a number as a string in C++, including [`sprintf()`](http://www.kernel.org/doc/man-pages/online/pages/man3/sprintf.3.html), [`boost:lexical_cast()`](http://www.boost.org/doc/libs/1_52_0/doc/html/boost_lexical_cast.html), and others. See [The String Formatters of Manor Farm](http://www.gotw.ca/publications/mill19.htm) for a good comparison and additional suggestions. In addition, C++11 has `std::to_string`. Your compiler may or may not have it yet.