Connect with Expertise | Find Experts, Get Answers, Share Insights

How do I convert string type to int?

 
Join Date: Jan 2010
Posts: 30
#1: Jan 28 '10
The answers i found sucked so maybe someone can shed some new light on the situation.

I have a 2-dimensional array of string type

string string1[2][4];

string1[0][0] = integer
string1[0][1] = string
string1[0][2] = float
string1[0][3] = integer

i need to read all of it into 1 two-dimensional array but when its a string type how do i get the integers to be an integer???

 
Join Date: Jan 2010
Posts: 30
#2: Jan 28 '10

re: How do I convert string type to int?


i guess i figured it out but every other answer i saw was soo complicated for some reason. all i did was

float floatNumber = atof(string1[0][2].c_str());
Banfa's Avatar
E
M
C
 
Join Date: Feb 2006
Location: South West UK
Posts: 7,124
#3: Jan 28 '10

re: How do I convert string type to int?


If you are using string then you are using C++. The C++ way to do this would be a stringstream.

Expand|Select|Wrap|Line Numbers
  1. float floatNumber;
  2. stringstream sstream(string1[0][2]);
  3. stream >> floatNumber;
  4.  
Reply