今天编写C++代码时,出现了错误,如下:
'strcmp' was not declared in this scope
代码部分如下:
include
#include
using namespace std;
#include
using namespace std;
//抽象产品类 男人
class Man
{
public:
virtual void makeM() = 0;
};
//具体产品类 白色男人
class WhiteMan : public Man
{
public:
void makeM()
{
cout << "I'm a white man."<< endl;
}
};
//具体产品类 黄色男人
class YellowMan : public Man
{
public:
void makeM()
{
cout << "I'm a yellow man." << endl;
}
};
//具体产品类 黑色男人
class BlackMan : public Man
{
public:
void makeM()
{
cout << "I'm a black man." << endl;
}
};
while (strcmp(t.c_str(), e.c_str()) != 0)
{
cout << "请输入标识符 ( 首字母大写 ):";
cin >> t;
if (strcmp(t.c_str(), y.c_str()) == 0)
{
man_y->makeM();
woman_y->makeW();
}
else if (strcmp(t.c_str(), w.c_str()) == 0) {
man_w->makeM();
woman_w->makeW();
}
else if (strcmp(t.c_str(), b.c_str()) == 0) {
man_b->makeM();
woman_b->makeW();
}
else if (strcmp(t.c_str(), e.c_str()) == 0) { //输入exit退出系统
cout << "退出" << endl;
}
else {
cout << "输入的标识符有误,请重新输入!" << endl;
}
cout << endl;
}
经过在网上查询得知:
1.必须再加上#include
#include<iostream>
#include<string>
#include <string.h>
using namespace std;
也就是说strcmp不在C++标准库中,需要单独包含strcmp所在的头文件。
2.或者加上#include
#include <cstring>
using namespace std;
原文链接: https://www.cnblogs.com/mjhjl/p/15368336.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/214170
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!