W
wreckingcru
I'm trying to tokenize a C++ string with the following code:
#include <iostream>
#include <stdio>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
char *temp_string;
char *new_string;
char *delim = " ";
cout <<"Please enter word: ";
cin >> new_string;
temp_string = strtok(new_string, delim);
while (temp_string != NULL)
{
cout<<temp_string<<endl;
temp_string = strtok(NULL, delim);
}
}
Here's my output:
Please enter word: This is a test
This
I never get more than the first word out!!! I'm using "g++ file.cpp"
with no flags.
I'm certain the flags are somehow wrong - I can't seem to figure out
anything wrong with my code.
Please advise?!
#include <iostream>
#include <stdio>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
char *temp_string;
char *new_string;
char *delim = " ";
cout <<"Please enter word: ";
cin >> new_string;
temp_string = strtok(new_string, delim);
while (temp_string != NULL)
{
cout<<temp_string<<endl;
temp_string = strtok(NULL, delim);
}
}
Here's my output:
Please enter word: This is a test
This
I never get more than the first word out!!! I'm using "g++ file.cpp"
with no flags.
I'm certain the flags are somehow wrong - I can't seem to figure out
anything wrong with my code.
Please advise?!