C++: Can someone help me out?

@mchu519 (465)
United States
November 19, 2006 1:33am CST
How would you convert a string "1234" to int "1234"? I appreciate it.
4 responses
@ladysun (635)
• United States
19 Nov 06
j=atoi("1234"):
@mchu519 (465)
• United States
19 Nov 06
Wow thanks for the response. Let me try it out.
@mchu519 (465)
• United States
19 Nov 06
It's not working. Can you help me out? Here is my code: int j; string ch; ch = "1234"; j=atoi(ch); cout
@mchu519 (465)
• United States
19 Nov 06
but when I do j=atoi("1234") it works.
@saumav (180)
• India
15 Dec 06
the prototype of atoi(alphabet to integer) is: int atoi(const char *); So string datatype won't work on it u can use it like this way: char *str="1234"; int no=atoi(str); printf("\n%d", no); But this method is deprecated these days. The better method is: char *str="1234"; int no; sscanf(str, "%d", &no)) printf("%d", no); and if u want to do it in C++ there's a different way. Do u want 2 know it? Tell me if it helped u
@mchu519 (465)
• United States
16 Dec 06
Thanks, but I used an alternative way that is a lot more complicated. I have already submitted the programming project. Its suppose to be a database program where I can retrieved records by entering a unique id. This programmed can load a bunch of records, add one record a time, list all the records in database, show a record at a time with detail, and delete a record. I got full marks. Now I have to do the same program, but use a more efficient method, which is B-tree. I have trouble with this one. Can anyone give me their source code for B-tree? Thanks.
@saumav (180)
• India
15 Dec 06
I'm adding u as friend to tht u can reply 2 me.
• Pakistan
13 Dec 06
use atoi() function to convert
@iwyrobi (282)
• Indonesia
15 Dec 06
ch= "1234"; j=atoi(&ch); have a try