#include < string .h >
void main()
{
string aaa = " abcsd d " ;
printf( " looking for abc from abcdecd %s\n " ,
(strcmp(aaa, " abc " )) ? " Found " : " Not Found " );
}
Cannot execute correctly, hint that string type is not defined
and the following:
#include < string >
using namespace std;
void main()
{
string aaa = " abcsd d " ;
printf( " looking for abc from abcdecd %s\n " ,
(strcmp(aaa, " abc " )) ? " Found " : " Not Found " );
}
The string compiler here is known, but strcmp don't know it?
General A C + + old band ". H "Library files for extensions, such as iostream.h, have one in the standard library after the new standard." H "extension of the corresponding, the difference in addition to a lot of improvements in the latter, there is one thing is that the latter stuff into the" STD "name space.
But only string was special.
The problem is that C + + is compatible with C's standard library, and C's standard library also happens to have a header file named "String.h", which contains some commonly used C string processing functions, such as the strcmp mentioned by the landlord.
This header file has nothing to do with the C + + string class, so <string> is not <string.h> "upgrade", they are unrelated to the two header files.
To achieve the purpose of the landlord, such as at the same time:
#include < string .h >
#include < string >
using namespace std;
Or
#include < cstring >
#include < string >
Where <cstring> is the <string.h> corresponding to the C standard library, but is wrapped with the Std namespace version.