Hello,

I am trying to understand how to use C-style strings in C++. My goal is to store a C-style strings into a string type array.

If I pass "This is a test" into word_token, it displays:
This
Is
A
test

So from here I believe my setup is almost right, I'm just having problems passing these into a string type array
Does not print out "This" as I expect it too
myArray[*token] ;
cout << myArray[0] ;

void word_token(char *str){ 
    string myArray[256]; // assuming str <= 256 words
    char spaces[] = " ";  // deliminator
    char *token = strtok(str, spaces); // creates token when a space is found

    while (token){
        cout << token << endl;
        toke = strtok(NULL, spaces);
        //myArray[*token];    //this does not work*
        //cout << myArray[0];
}

What's up with line 8? You use toke and I can't find its declaration.

commented: Sorry, that should be token +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.