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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting

Status
Not open for further replies.

sharktlp

Technical User
Nov 19, 2003
5
0
0
US
I have a file that contains employee info such as name telephone address id salary. I used in.getline to store them in respective fields (employee.name, employee.id) the problem is i used char for ID so i can use in.getline but i need to convert it to int so i can sort by id. how can i convert employee.id to int?
 
What's a problem? Use Standard atoi() from <cstdlib>:
Code:
char* chr;
int   i;
...
i = atoi(chr);
// or if std:string text:
string s;
...
i = atoi(s.c_str());
Warning: atoi() returns 0 if its arg is NaN (i.e. atoi(&quot;Junk&quot;) == 0;)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top