Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Nov 13th, 2006, 9:09 PM   #1
Mcoy
Newbie
 
Mcoy's Avatar
 
Join Date: Mar 2006
Posts: 20
Rep Power: 0 Mcoy is on a distinguished road
About atoi function and const chars...

string temp;
    char temp2[3];
    int num_of_values;
    
    getline (myfile,temp);
    
    for(int i(0); i < 3; i++)
    {
            temp2[i] = temp[i];
    }
    
    num_of_values = atoi(temp2);

The goal of the above code was to read a line from a file (with the getline function) and convert it from string type to integer type with atoi(). When supplying the atoi function with the string, the compiler gave me an error saying that atoi did not accept strings, only const char*s. So I had to use the for loop that you see in my code to change each letter from the string to a char array. -Seems very redundant to me considering a string is simply a character array, or am I mistaken?
What is a better/more efficient/intuitive way to read integers into my program from a file?
Mcoy is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GOTO Sys. Tray Src. (code Snippet) Cipher Show Off Your Open Source Projects 1 Oct 17th, 2006 2:38 PM
BlitzPlus antros Other Programming Languages 2 Mar 3rd, 2006 1:24 AM
Jackpot game zorin Visual Basic 3 Jun 10th, 2005 2:19 PM
How can i take const char* in function... hanjun C++ 5 May 23rd, 2005 4:49 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC