Friday, September 27, 2013

Adding char to string in C++

I work with Eclipse & Arduino.

I want to add a char to a string. I tried to use append,insert ( yet these can not be resolved)
I tried to use += yet when i print the string it always have one char.Basically i deletes the string & writes only the new char i want to add in.
I tried moreover concat & it does the same thing.Also strcat gives me headache with the operands cause it needs a const char pointer & i want to add a char that changes.

while (theSettings.available()) {character = theSettings.read();if(character == '/')         {    // Comment - ignore this line    while(character != '\n'){        character = theSettings.read();    }} else if(isalnum(character)){  // Add a character to the description    Serial.println(character);    description +=character;    //description.concat(character);    Serial.println(description);}

It sounds like what you want (for convenience) is the String object class available with the Arduino library.
http://arduino.cc/en/Reference/StringObject

No comments:

Post a Comment