This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: converting int to string


Hi Colin,

>Sorry, if this is a rather easy one, but can someone tell me how to convert an int, or any other value ,into a string?

Whew, an easy one!

--- Append.h ---
#include <string>

// Appends the value onto the end of the given string.
// Adds a space inbetween them.
void Append(std::string& ioString, int inValue);
--- End Append.h ---

--- Append.cpp ---
#include "Append.h"
#include <string>
#include <sstream>

void Append(std::string& ioString, int inValue) {
std::ostringstream o;
o << ioString << " " << inValue;
ioString = o.str();
}
--- End Append.cpp ---

Ta-dah!

--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]