maniacbug / StandardCplusplus

Standard C++ for Arduino (port of uClibc++)
588 stars 182 forks source link

Cannot convert int to string using library #5

Closed myrtleTree33 closed 1 year ago

myrtleTree33 commented 11 years ago

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.

nicolaspanel commented 11 years ago

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

String itoa(int arg) {
   return String(arg);
}
maniacbug commented 1 year ago

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() {}