Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;预期不合格id“;对于气流 我写了下面的C++程序,但在使用了 OutjStudio.OPEN()/Cux>的那一行,它不断告诉我,“未知类型名称”OutoSukes“和”预期不合格ID“存在错误。p> 我是C++新手,我想我只是抄下了我的课本,所以我弄不清楚哪里出了问题。如果这是一个很简单的错误,请原谅我_C++_Ofstream - Fatal编程技术网

&引用;预期不合格id“;对于气流 我写了下面的C++程序,但在使用了 OutjStudio.OPEN()/Cux>的那一行,它不断告诉我,“未知类型名称”OutoSukes“和”预期不合格ID“存在错误。p> 我是C++新手,我想我只是抄下了我的课本,所以我弄不清楚哪里出了问题。如果这是一个很简单的错误,请原谅我

&引用;预期不合格id“;对于气流 我写了下面的C++程序,但在使用了 OutjStudio.OPEN()/Cux>的那一行,它不断告诉我,“未知类型名称”OutoSukes“和”预期不合格ID“存在错误。p> 我是C++新手,我想我只是抄下了我的课本,所以我弄不清楚哪里出了问题。如果这是一个很简单的错误,请原谅我,c++,ofstream,C++,Ofstream,这是我的密码: #include <iostream> #include <fstream> #include <cmath> #include <vector> #include <boost/random.hpp> #include <boost/random/mersenne_twister.hpp> #include <boost/random/normal_distribution.hpp> #incl

这是我的密码:

#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;

}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
std::流出流的流量;
out_stream.open(“output.txt”);
int main()
{
std::cout您不能这样做

out_stream.open("output.txt");
函数的外部。将其放入main()中

intmain()
{
out_stream.open(“output.txt”);

库特谢谢你!!但好奇的是,这个限制背后有没有道德?为什么不允许它在另一个函数之外使用它的成员函数?没有“道德”涉及到的语言规则只是说代码应该在函数中。实际上,您可以使用它的一个构造函数直接在声明中打开文件,该构造函数为您调用open
std::ofstream out_stream(“output.txt”);
。感谢构造函数方法@BoPersson
int main()
{
    out_stream.open("output.txt");
    std::cout<<"hello world!";
    return 0;

}