0
void getCommands(char * cstr,char * p,string *userInput,string Input)
{
     
     string currentCommand = "";
     strcpy (cstr, userInput.c_str());
     p = strtok (cstr," ");
       while (p!=NULL)
   {
    p=strtok(NULL," ");
    cout << p;
}

ERROR
`c_str' has not been declared
request for member of non-aggregate type before '(' token


I have #include <cstring>
WHY STILL DONT WORK!!!!!!!!!!!!!!!!!!!!! :(:(:(

Edited by tech9x: n/a

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by jonsca
Featured Replies
  • 1
    jonsca 1,059   6 Years Ago

    [QUOTE=geojia]Edit: NVM your problem isn't the c_str(), userInput is already char. [CODE] strcpy (cstr, userInput); [/CODE][/QUOTE] userInput is a [icode] string * [/icode] which means you have to dereference it using the -> operator, so [icode] userInput->c_str() [/icode] @OP You still will need to include [icode] <string> [/icode] if you … Read More

0

try

#include <string>

string.c_str() is a method for a string, and has nothing to do with including the cstring

0

Edit:
NVM your problem isn't the c_str(), userInput is already char.

strcpy (cstr, userInput);

Edited by geojia: n/a

1

Edit:
NVM your problem isn't the c_str(), userInput is already char.

strcpy (cstr, userInput);

userInput is a string * which means you have to dereference it using the -> operator, so userInput->c_str() @OP You still will need to include <string> if you are using std::string in your code.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.