在下面的C++程序中,我包含string.h文件,并且我成功地在其中实例化C++字符串类并调用其成员函数之一:size().
#include <iostream>
#include <string.h>
using namespace std;
int main( )
{
string s = "Hello";
cout << "String: " << s << endl;
cout << "Size of string: " << s.size() << endl;
cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
String: Hello
Size of string: 5
Run Code Online (Sandbox Code Playgroud)
我正在使用Dev-C++ 4.9.9.2
我的问题:string.h文件不提供操作C字符串的功能吗?它不包含C++字符串类的定义吗?那么,如何在不使用的情况下访问C++字符串类#include <string>呢?我的理解是string.h文件是C字符串库文件并<string>包含C++字符串库文件.这不对吗?
谢谢!