#include <iostream>
#include <string>
int main()
{
usingnamespace std;
char response[256];
cout << "What is your name? ";
cin.getline(response,256);
if (strlen(response) == 0)
cout << "You must tell me your name...";
else
cout << "It's nice to meet you, " << response;
return 0;
}
A book says to type this in as a tutorial, but when you run it , it gives an error code strlen not declared in this scope
They proceed to go on explaining as if it worked, but it didn't for me?
Don't use that book. You're missing an include (<cstring>), however you should use none of the functions from that header in C++.
In correct C++, the program looks like this:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <string>
int main()
{
usingnamespace std;
string response;
cout << "What is your name? ";
getline(cin,response);
if (response.empty())cout << "You must tell me your name...";
else cout << "It's nice to meet you, " << response;
}
Game programming books aren't exactly known for their quality (to put it mildly).
Viable choices are The C++ Primer, Accelerated C++ and Thinking in C++.
I have a few books
I abandoned C++ for Dummies, it was not explained well at all. It gave examples and explained only some of what was going on but not all and the writer explanation was confusing
The book I was using for this forum tutorial was Learn to Program with C++ (1993), I liked it cuz it explained everything as if you had no knowledge of C++ or math. It explained line for line of code and what this does and that does before proceeding.