#include <iostream>
#include <string>
#include <cctype>
using std::cin; using std::cout; using std::endl;
using std::string;
int main(void)
{
// read a string
string str;
cout << "Please enter the string: ";
getline(cin, str);
// convert the first word into upper case
for (string::size_type i = 0; i != str.size() && !isspace(str[i]); ++i)
str[i] = toupper(str[i]);
// display the result
cout << "Converted string is: ";
cout << str;
cin.get();
return 0;
}
The code is simple enough. But if I commented line 3, I suppose the program will not run since the function isspace is not defined. However, it also runs correctly.
I tested on MS Visual Studio 2010 professional and Code::blocks 13.12. All these two can run the program without trouble.
the standard library headers are allowed to include each other (and even parts of each other) arbitrarily: it's actually quite common that some #include's may be omitted, but the resulting code is non-portable.
Thanks for the explanation. I believe it's still a good habit to include all the corresponding headers at the beginning, even not required for some compiler.