LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-23-2005, 09:49 PM   #1
nelnel
Member
 
Registered: May 2005
Posts: 47

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


hi,
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-23-2005, 11:04 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

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

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

ss << int_tmp;
str_tmp = ss.str();
 
Old 08-23-2005, 11:46 PM   #3
nelnel
Member
 
Registered: May 2005
Posts: 47

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

i try it later
 
  


Reply


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 08:49 AM
Converting int value to char liguorir Programming 8 05-23-2004 07:21 PM
int(char(254)) becomes kalleanka Programming 2 02-17-2004 03:35 PM
int, long in char * marek Programming 10 09-01-2003 10:43 AM
java covert double into string iceman47 Programming 10 05-28-2003 10:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 AM.

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