在我代码的第5行,编译器引发了一个错误。“错误:应为未限定的IDstd::string send(消息);{
”
这是什么错误?我怎么修好它?
这是我的代码:
#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
造成的。
但也存在其他问题。它看起来像是要创建一个send
函数,但分号;
使它看起来像是用message
构造的全局变量send
的声明,然后是一个代码块,因为它不是函数的一部分,所以语法错误。