StandardCplusplus icon indicating copy to clipboard operation
StandardCplusplus copied to clipboard

Cannot convert int to string using library

Open myrtleTree33 opened this issue 12 years ago • 1 comments

Hello, how do I convert an int to a string using standardcplusplus?

I tried the conventional way of using stringstreams, but it gives an error:

std::string itoa(int arg) { stringstream aa; aa << arg; return aa.str();

}

The error reported is error: 'string' does not name a type.

myrtleTree33 avatar Jun 01 '13 12:06 myrtleTree33

With Arduino library, you can convert int to String using this :

String itoa(int arg) {
   return String(arg);
}

nicolaspanel avatar Jun 07 '13 08:06 nicolaspanel

Hi, I compiled this just now and it worked no problem. Perhaps paste in the complete code example demonstrating failure? Thanks!

#include <StandardCplusplus.h>
#include <sstream>

using namespace std;

string itoa(int arg) 
{
  stringstream aa;
  aa << arg;
  return aa.str();
}

void setup() {}
void loop() {}

maniacbug avatar Jul 05 '23 23:07 maniacbug