![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 20
Rep Power: 0
![]() |
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? |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |