C++需要不合格的id

  • 本文关键字:id 不合格 C++ c++
  • 更新时间 :
  • 英文 :


在我的代码的第五行,编译器引发了一个错误"错误:需要不合格的idCCD_ 1";

这是什么错误?我该如何修复它?

这是我的代码:

#include <iostream>
#include <fstream>
std::string message = "blank";
std::string send(message); { // here it raises the error
std::ofstream MyFile("messagepy.txt");
std::ofstream MyFile; << "Files can be tricky, but it is fun enough!";
}
// // // // // // // // // // // // // //
int main() {
std::cout << "defining is done.";
}

您有一些语法错误。不确定你的代码要做什么,但我的猜测是:

#include <iostream>
#include <fstream>
#include <string>

void send(std::string message)
{
std::ofstream MyFile("messagepy.txt");
MyFile << message;
MyFile << "Files can be tricky, but it is fun enough!";
}
int main()
{
std::string message = "blank";
send(message);
std::cout << "defining is done." << std::endl;
}

我相信错误是因为您没有#include <string>

但也存在其他问题。它看起来有点像你想要创建一个send函数,但分号;使它看起来像是用message构造的全局变量send的声明,然后是一个代码块,这是一个语法错误,因为它不是函数的一部分。

最新更新