So, I made a program that will let a user enter a command, like print message
and it will show him the message he entered.
For example, if he types in: print Hello
, the console's output will be Hello
.
Now, here's my code:
#include <iostream>
using namespace std;
int main()
{
string command;
start:
cout << ">>> ";
cin >> command;
if (command.substr(0,5) == "print")
{
if (command.substr(6,command.end) != "")
{
cout << command.substr(6,command.end);
goto start;
}
else
{
cout << "Usage: print text";
goto start;
}
}
}
The thing is I get an error:
no matching function for call to 'std::basic_string::substr(int, )'|
and I'm not sure if I specified the substring length correctly. I wanted the first if to check if the first five words were print
.