Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-23-2005, 10:49 PM   #1
Registered: May 2005
Posts: 47

Rep: Reputation: 15
how to covert int to string/char type?

i want to covert the integer type variable to string/char type. In window, i will use CString, but now in linux i can't do that.

Then ,any method/function can be used to convert it, like this:

int int_tmp = 2;
string str_tmp = int_tmp:

thx alot.
Old 08-24-2005, 12:04 AM   #2
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Using pure C you could use sprintf.
char buffer[256];
int int_tmp;
sprintf(buffer, "%d", int_tmp);
string str_tmp = buffer;
Using C++ you can use a stringstream.

stringstream ss; // #include <sstream> for this
int int_tmp = 2;
string str_tmp;

ss << int_tmp;
str_tmp = ss.str();
Old 08-24-2005, 12:46 AM   #3
Registered: May 2005
Posts: 47

Original Poster
Rep: Reputation: 15
thx, i get it

i try it later


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
char to int: a twist Guru3 Programming 5 12-05-2004 09:49 AM
Converting int value to char liguorir Programming 8 05-23-2004 08:21 PM
int(char(254)) becomes kalleanka Programming 2 02-17-2004 04:35 PM
int, long in char * marek Programming 10 09-01-2003 11:43 AM
java covert double into string iceman47 Programming 10 05-28-2003 11:51 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:54 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration