string to int

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2008
Posts: 98
Reputation: Nemoticchigga is an unknown quantity at this point 
Solved Threads: 2
Nemoticchigga Nemoticchigga is offline Offline
Junior Poster in Training

string to int

 
0
  #1
May 7th, 2008
Does anyone know how to convert a "String^" data type in a visual studio 2005 forms app to an "int"? Ive tried atoi and casting to no success. Any ideas? Thanks.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,411
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 114
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: string to int

 
0
  #2
May 7th, 2008
try
  1. Int32::Parse(stringname)
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: string to int

 
0
  #3
May 7th, 2008
C++/CLI handles boxing and unboxing implicitly. Either of these work just peachy:
  1. using namespace System;
  2.  
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. String^ s = "123";
  8. int x = Convert::ToInt32(s);
  9.  
  10. std::cout << x * x << '\n';
  11. }
  1. using namespace System;
  2.  
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. String^ s = "123";
  8. int x = Int32::Parse(s);
  9.  
  10. std::cout << x * x << '\n';
  11. }
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,839
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 298
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: string to int

 
0
  #4
May 7th, 2008
[edit] misread the OP
Last edited by niek_e; May 7th, 2008 at 12:02 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 98
Reputation: Nemoticchigga is an unknown quantity at this point 
Solved Threads: 2
Nemoticchigga Nemoticchigga is offline Offline
Junior Poster in Training

Re: string to int

 
0
  #5
May 7th, 2008
Thanks, but new issue.

  1. String^ comPort = "COM" + this->RS232CommPortNum->Value;
  2. int baudRate = Convert::ToInt32(this->cbBaudRate->ValueMember);
  3. SerialPort com = gcnew SerialPort(comPort, baudRate);

error C2664: 'System::IO:orts:erialPort:erialPort(System::ComponentModel::IContainer ^)' : cannot convert parameter 1 from 'System::IO:orts:erialPort *' to 'System::ComponentModel::IContainer ^'

this should work but it is giving me a wierd error. There are seven different overloads for SerialPort() and I dont understand why it is interpreting it this way. Any suggestions? Thanks again.

I want to use the SerialPort(SYSTEM string^ portname, int baudrate)
Last edited by Nemoticchigga; May 7th, 2008 at 12:10 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: string to int

 
0
  #6
May 7th, 2008
gcnew creates a new managed reference object. You need to declare the variable holding the object as a managed reference:
  1. SerialPort^ com = gcnew SerialPort(comPort, baudRate);
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 98
Reputation: Nemoticchigga is an unknown quantity at this point 
Solved Threads: 2
Nemoticchigga Nemoticchigga is offline Offline
Junior Poster in Training

Re: string to int

 
0
  #7
May 7th, 2008
Great, I dont have much experience with visual studio forms, thanks a lot for your help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC