0

Hi Everyone,

I'm working in with a file and somewhere in it I'm reading a number that i know it's starting and endig position n the file and then i store it in an string*. But at the end I need to convert this string to the int value. I don't know how I can make it.

I was trying to use atoi by writing:

for(int l=start+11;l<end;l++)
          {
            fseek(pFile,l,SEEK_SET);

            //reads one char(byte) of data from file                                                              
            fread(&onechar,sizeof(onechar),1,pFile);

          //    cout<<onechar;                                                                                    
              num_as_str+=onechar;
            // strcat(num_as_str,temp);                                                                           
          }

             num= atoi ( num_as_str );
             cout<< num_as_str<<'\n';

but it gives me the following error:
error: cannot convert 'std::string*' to 'const char*' for argument '1' to 'int atoi(const char*)'

I know it means that i need to change of the num_as_str but i don't know how i can do it?

The num_as_str that i'm getting looks like: 9.324e-5 so it's another reason i think atoi might not solve the problem easily.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by nbaztec
Featured Replies
  • You can use string streams to convert a string into a number. [URL="http://programmingexamples.net/index.php?title=CPP/StringStream"]this is from dave's new wiki[/URL] Read More

0

I know it means that i need to change of the num_as_str but i don't know how i can do it?

num_as_str.c_str()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.