title: Problems when using strtok function
body: <p>Good morning to everybody, :)</p>
  
  <p>I have writen a code in C++ that reads information from a txt file. It takes the information in the first row saving it in a string and then I want to work with this info. I want to read this string and when it finds a "|" character it must jump to a new line. Its something quite easy but I'm having problems when executing and I've been trying to find the problem for hours and I haven't suceed. :( I attached the code.</p>
  
  <p>Thanks in advance for your help.</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
  
      ifstream ifs( "C:\\a\\text.txt" );
      string temp;
  
      getline( ifs, temp ); 
      cout&lt;&lt;temp&lt;&lt;endl;
  
      string * pch;
      pch = strtok (temp,"|");
  
      while (pch != NULL)
      {
          printf ("%s\n",pch);
          pch = strtok (NULL, "|");
      }
  
      system("pause");
      return 0;
  
  }
  </code></pre>