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.

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 article has been dead for over six months. Start a new discussion instead.