944,155 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2458
  • C++ RSS
Oct 28th, 2005
0

Coverting varibles

Expand Post »
I was wondering if there's a way to convert a CString or a char *x[10] to a int? I know I can convert int to CString, but can it go the other way?
Thanx,
Atrus
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atrusmre is offline Offline
64 posts
since Mar 2005
Oct 28th, 2005
0

Re: Coverting varibles

Sure, why not?
Reputation Points: 23
Solved Threads: 23
Posting Pro in Training
Puckdropper is offline Offline
494 posts
since Jul 2004
Oct 28th, 2005
0

Re: Coverting varibles

atoi for converting a char * to an int C or Or stringstreams for C++
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004
Oct 28th, 2005
0

Re: Coverting varibles

for CString (I assume you mean Microsoft MFC CString class)
C++ Syntax (Toggle Plain Text)
  1. // convert from CString to int just requires typcasting the CString
  2. CString str = "123";
  3. int n = atoi((LPCTSTR)str);
  4.  
  5. // convert from int to CString
  6. str.Format("%d", n);
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Oct 29th, 2005
0

Re: Coverting varibles

ok so would the following statement work then?
C++ Syntax (Toggle Plain Text)
  1. char *str[5];
  2. str[0] = "123";
  3. int n = atoi((LPCTSTR)str[0]);
and yes I meant MFC CStrings... Sorry I didn't mentionthat
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atrusmre is offline Offline
64 posts
since Mar 2005
Oct 29th, 2005
0

Re: Coverting varibles

When in doubt, test it out!
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 30th, 2005
0

Re: Coverting varibles

yeah I thought of that AFTER I posted
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atrusmre is offline Offline
64 posts
since Mar 2005
Oct 30th, 2005
0

Re: Coverting varibles

Quote originally posted by atrusmre ...
ok so would the following statement work then?
C++ Syntax (Toggle Plain Text)
  1. char *str[5];
  2. str[0] = "123";
  3. int n = atoi((LPCTSTR)str[0]);
you don't need to typecast character arrays -- that typecast is to convert a CString object to const char*.
C++ Syntax (Toggle Plain Text)
  1. char *str[5];
  2. str[0] = "123";
  3. int n = atoi(str[0]);
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Cbuilder Fullscreen form how to ???
Next Thread in C++ Forum Timeline: Store large numbers in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC