Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting integer to string

Status
Not open for further replies.

dbarne

Technical User
Sep 10, 2002
2
0
0
US
Using visual c++, is there a way to convert a number to a string? For instance say I'm trying to generically populate a 3-d array, and I just want each block to fill with the values of the nested for loop but as a string so I can see where I am at, for instance array(0,0,0) would hold the value 000, and so on
 
Hey,

use:

atoi (for an integer)
atof (for a float)
atol (for long)
atoll (for double long)

ex:

int i_converted;
i_converted = atoi (m_strToBeConverted);

or:

double currentdeposit = atof (m_strMoney);

that is the jist. Might want to read up on the restrictions of each one.
 
So since I want to change an integer to a string can I use itoa?
 
yes use itoa (your integer number,the string that will store
the string value of the number it can be char*,the base of the integer number(2:binary,10:decimal,16:hexadecimal))

Hail to all metal listeners...
 
int a;
a=30;
printf("int to char:%s,a(atoi));

simple example



 
I actually misread your question wrong. I see u want to go from int to cstring, not cstring to int.

here is the code:

CString m_strMoney;

m_strMoney.Format("%f",currentdeposit);

"%f" = float
"%i" = int

there are more.
 
char* s;...
int currentdeposit;
sprintf(s, "%d", currentdeposit);


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
CString cs;
cs.Format("%i %5i %-5i %x %X %f %3f %8.3f",
3.14,3.14,3.14,3.14,3.14,3.14,3.14,3.14);


Try it out!

Andreas

Greetings Andreas
email is invalid, because of spam
email me to amosmann[at]dualis[dot]net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top