C++ string 类相关知识

/*

ISO/ANSI C++标准通过添加string类扩展了C++库,因此现在可以string类型的变量(使用C++的话

说是对象)而不是字符数组来存储字符串。读者将看到,string 类使用起来比数组简单,同时提供了将字

符串作为一种数据类型的表示方法。

要使用string类,必须在程序中包含头文件string。string类位于名称空间std中,因此您必须提供一条

using编译指令,或者使用std :: string来引用它。string类定义隐藏了字符串的数组性质,让您能够像处理普

通变量那样处理字符串。程序清单4.7说明了string对象与字符数组之间的一些相同点和不同点。

*/

#include 
#include 
int main()
{
    using namespace std;
    char charr1[20];
    char charr2[20]="jaguar";
    string str1;
    string str2="panther";

    cout<<"Enter a kind of feline:";
    cin>>charr1;
    cout<<"Enter another kind of feline:";
    cin>>str1;
    cout<<"Here are some felines:\n";
    cout<

你可能感兴趣的:(c++,开发语言)