C++ ';struct std::string';没有名为'的成员;c#u字符串';

C++ ';struct std::string';没有名为'的成员;c#u字符串';,c++,C++,我收到错误消息“struct std::string”在我的代码中没有名为“c_string”的成员。我是根据我的教科书中的一段代码,成功地用我的编译器编写了一段代码,来构建这段代码的结构的。哪些语法错误可能导致此特定错误?(在11号线上) #包括 #包括 #包括 #包括 #包括 使用名称空间std; int main() { 字符串payroll=“table.dat”; 流切; MyCout.open(payroll.c_string()); if(mycut.fail()) { couts

我收到错误消息“struct std::string”在我的代码中没有名为“c_string”的成员。我是根据我的教科书中的一段代码,成功地用我的编译器编写了一段代码,来构建这段代码的结构的。哪些语法错误可能导致此特定错误?(在11号线上)

#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
字符串payroll=“table.dat”;
流切;
MyCout.open(payroll.c_string());
if(mycut.fail())
{

cout
std::string
没有名为
c_string
的函数或成员,因此出现了确切的编译器错误。例如,您可以在网上找到大量有关可以调用标准库对象的成员和函数的信息

如果您仔细查看所引用的代码,就会发现您打算使用
c_str()

他们的代码:

ofstream outFile;
outFile.open(filename.c_str());
您的代码:

ofstream MyCout;
MyCout.open(payroll.c_string());
解决方案:

ofstream MyCout;
MyCout.open(payroll.c_str());

函数名为
c_str()
您需要仔细查看正在比较的代码,或者使用最新的IDE,其中显示了您可以使用的功能。我正在投票关闭一个印刷错误我发现了错误-我认为我查看它太快了太多次。它应该是c_str,而不是c_字符串。对于这个愚蠢的问题,很抱歉,但感谢您的有用回复非常感谢。
ofstream MyCout;
MyCout.open(payroll.c_string());
ofstream MyCout;
MyCout.open(payroll.c_str());