Good morning to everybody, :)
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.
Thanks in advance for your help.
#include <string>
#include <fstream>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
ifstream ifs( "C:\\a\\text.txt" );
string temp;
getline( ifs, temp );
cout<<temp<<endl;
string * pch;
pch = strtok (temp,"|");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, "|");
}
system("pause");
return 0;
}