[英]“Expected unqualified-id” for ofstream
I wrote the following C++ program, but at the line where I used out_stream.open()
, it keeps telling me that there are errors about "unknown typename 'out_stream'" and "Expected unqualified-id". 我编写了以下C ++程序,但在我使用
out_stream.open()
的行中,它一直告诉我有关“unknown typename'out_stream'”和“Expected unqualified-id”的错误。
I am new to C++ and I think I just copied down the lines from my textbook, so I can't figure out where it's wrong. 我是C ++的新手,我想我只是从我的教科书中删除了一行,所以我无法弄清楚它的错误。 Please bear with me if it is a really simple mistake.
如果这是一个非常简单的错误,请耐心等待。
Here's my code: 这是我的代码:
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <boost/random.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/math/distributions.hpp>
std::ofstream out_stream;
out_stream.open("output.txt");
int main()
{
std::cout<<"hello world!";
return 0;
}
You cannot to this 你不能这样
out_stream.open("output.txt");
outside of a function. 功能之外。 Put it inside the main().
把它放在main()中。
int main()
{
out_stream.open("output.txt");
std::cout<<"hello world!";
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.