Jun 4, 2002 #1 Maurader Technical User May 8, 2002 59 CA How do i convert an integer to a string?? actually, i need to do string line; line = "G" + getIntVal() + getStringVal(); where getIntVal returns an integer and getStringVa() retrns a string Thanks!
How do i convert an integer to a string?? actually, i need to do string line; line = "G" + getIntVal() + getStringVal(); where getIntVal returns an integer and getStringVa() retrns a string Thanks!
Jun 4, 2002 #2 MKuiper Programmer Jan 29, 2002 364 NL #include <stdio.h> ... sprintf ( line, "G%d%s", getIntVal ( ), getStringVal ( )); Marcel Upvote 0 Downvote
Jun 4, 2002 Thread starter #3 Maurader Technical User May 8, 2002 59 CA I get error error C2664: 'sprintf' : cannot convert parameter 1 from 'const char *' to 'char *' Upvote 0 Downvote
Jun 4, 2002 #4 MKuiper Programmer Jan 29, 2002 364 NL type cast it: sprintf ( (char *)line, .... Marcel Upvote 0 Downvote
Jun 4, 2002 Thread starter #5 Maurader Technical User May 8, 2002 59 CA thx! doh! still doesn't work! C:\ExtendPaths\NCParser.cpp(243) : error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *' Upvote 0 Downvote
thx! doh! still doesn't work! C:\ExtendPaths\NCParser.cpp(243) : error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
Jun 4, 2002 #6 Leibnitz Programmer Apr 6, 2001 393 CA you can use one of this codes: #include<stdio.h> ..... ... char buffer[15]; int iValue; sprintf( buffer,"%d",iValue ); or #include<stdlib.h> ..... ... char buffer[15]; int iValue; _itoa( iValue, buffer, 10 ); Upvote 0 Downvote
you can use one of this codes: #include<stdio.h> ..... ... char buffer[15]; int iValue; sprintf( buffer,"%d",iValue ); or #include<stdlib.h> ..... ... char buffer[15]; int iValue; _itoa( iValue, buffer, 10 );
Jun 4, 2002 #7 dharmon Programmer Mar 30, 2002 18 US sprintf works with char arrays not strings. sprintf( char * , char *format , ... ); string str sprintf( str.c_str , "%d" , value ); dl_harmon@yahoo.com http://agdn.cjb.net Upvote 0 Downvote
sprintf works with char arrays not strings. sprintf( char * , char *format , ... ); string str sprintf( str.c_str , "%d" , value ); dl_harmon@yahoo.com http://agdn.cjb.net
Jun 4, 2002 #8 jtm111 Programmer Jun 27, 2001 103 US Use the advantages of C++. #include <sstream> ostringstream ostr; int int_var; string str_var; ostr << "G" << int_var << str_var; cout << ostr.str(); // you can access the string as a char * string too char *v = ostr.str().c_str(); Upvote 0 Downvote
Use the advantages of C++. #include <sstream> ostringstream ostr; int int_var; string str_var; ostr << "G" << int_var << str_var; cout << ostr.str(); // you can access the string as a char * string too char *v = ostr.str().c_str();