C++ Primer第四版练习题-4.26

C++ Primer第四版习题--4.26

#include <iostream>
#include <cstring>

int main()
{
    const int buf_size = 1024;
    char *str1, *str2;
    str1 = new char[buf_size];
    str2 = new char[buf_size];
    std::cin >> str1 >> str2;
    int result;
    result = strcmp(str1, str2);
    if(result>0)
        std::cout << "str1 is bigger!\n";
    else if(result<0)
        std::cout << "str2 is bigger!\n";
    else
        std::cout << "equal!\n";
    delete [] str1;
    delete [] str2;
    return 0;
}

如果编译器报错

error: 'strcmp' was not declared in this scope

     result = strcmp(str1, str2);

                               ^

需要添加头文件<cstring>