繁体   English   中英

我包括了std,但是仍然出现错误,为什么呢?

[英]I included std, but I'm still getting an error, why is that?

我不确定我做错了什么,我对C ++很陌生,我包括了“字符串”库并使用了std。 但仍然出现错误,我没有包含所有代码,因为不必要

错误

./year.h:25:5: error: unknown type name 'string'; did you mean 'std::string'?
    string monthStr();
    ^~~~~~
    std::string

代码来源

#include <iostream>
#include <iomanip>
#include <string>
#include "Year.h"

using namespace std;
string Year::monthStr()
{
    if (m >= 1 && month <= 12)  return monthStrings[month - 1];
    else                        return "Unknown";
}

您的错误不在代码的该部分中。 在Year.h中,请查看。

您的year.h头文件可能存在问题,您可能忘记使用命名空间std来使用它,最好避免添加使用命名空间的东西以避免命名空间污染

只需使用:std :: string

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM