The diference between cstring and string

Today,when I write a program,fllowing:

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>

using namespace std;

int main()
{
#if 1
    string s = "word";
    string p1 = s + (s[s.size() - 1] == 's' ? " " : "s");

    cout << p1 << endl;
#endif

    system("PAUSE");
    return 0;
}

 

When I away the cstring ,the program will error in vs2017:

严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2679 二进制“<<”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换) 

 

The cstring header provides functions for dealing with C-style strings — null-terminated arrays of characters. This includes functions like strlen and strcpy. It's the C++ version of the classic string.h header from C.

The string header provides the std::string class and related functions and operators.

The headers have similar names, but they're not really related beyond that. They cover separate tasks.

posted @ 2018-06-04 15:14  Hk_Mayfly  阅读(153)  评论(0)    收藏  举报