title: C++ How to convert string to char*
body: <p>I need to convert a string to a char * for use in strtok_s and have been unable to figure it out. c_str() converts to a const char *, which is incompatible. </p>
  
  <p>Also, if someone could explain to me why the second strtok_s function (inside the loop) is necessary, it'd be a great help. Why do i need to explicitly advance the token rather than, for example, the while loop it is in, which fetches each line of a file consecutively, implicitly.</p>
  
  <pre><code>while( getline(myFile, line) ) { // Only one line anyway. . . is there a better way?
      char * con = line.c_str();
      token = strtok_s( con, "#", &amp;next_token);
      while ((token != NULL))
      {
          printf( " %s\n", token );
          token = strtok_s( NULL, "#", &amp;next_token);
      }
  }
  </code></pre>
  
  <p>related <a href="https://stackoverflow.com/questions/289347/using-strtok-with-a-string-argument-instead-of-char">question</a>.</p>