Quote:Original post by rip-off
you misspelled snprintf there
So sprintf is a no-no?
boost::lexical_cast<std::string>(myInteger)
Quote:Original post by rip-off
i read that sprintf and so on are major causes of bugs, so better to be safe than sorry.
snprintf is safer in my opionion, with the stringstream being safer again
what if you get on fine with sprintf and continue to use it in other situations until there is one that can cause a bug.
i don't like to encourage its use, esp in the beginners forum
int a = 65;cout << "The ascii value for '" << static_cast<char>(a) << "' is " << a << endl;
int num = 9;CString cs;cs.Format("%d", num);
Quote:Original post by fuchiefck
I never know what kind of strings are the best to work with... CString? std::string? or plain char*?
Quote:Original post by chbrules
I have an integer value, but I want it to be shown as a char. I don't mean ASCII values, I mean that if the int is equal to say, 128, I want the values 128 shown as chars. String class is applicable here too, probably would be easier for me? Thanks.
// Shares the same memory location. union u_type{ int i; char ch;};int main(){ u_type cnvt; cnvt.i = 65; cout << cnvt.ch << endl; // outputs 'A' return 0;}