Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.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
C++ &引用;不允许使用不完整的类型“;创建std::of流对象时_C++_Visual Studio 2013_Fstream_Ofstream - Fatal编程技术网

C++ &引用;不允许使用不完整的类型“;创建std::of流对象时

C++ &引用;不允许使用不完整的类型“;创建std::of流对象时,c++,visual-studio-2013,fstream,ofstream,C++,Visual Studio 2013,Fstream,Ofstream,Visual Studio抛出此奇怪错误: 不允许使用不完整的类型 当我尝试创建std::ofstream对象时。下面是我在函数中编写的代码 void OutPutLog() { std::ofstream outFile("Log.txt"); } 每当遇到此问题时,VisualStudio都会抛出该错误。为什么会发生这种情况?正如@Mgetz所说,您可能忘记了#包含 您没有得到未声明错误,而此不允许的不完整类型错误的原因与存在已定义但尚未完全定义的类型时发生的情况有关 看看这个例

Visual Studio抛出此奇怪错误:

不允许使用不完整的类型

当我尝试创建std::ofstream对象时。下面是我在函数中编写的代码

void OutPutLog()
{
     std::ofstream outFile("Log.txt");
}

每当遇到此问题时,VisualStudio都会抛出该错误。为什么会发生这种情况?

正如@Mgetz所说,您可能忘记了
#包含

您没有得到
未声明
错误,而此
不允许的不完整类型
错误的原因与存在已定义但尚未完全定义的类型时发生的情况有关

看看这个例子:

#include <iostream>

struct Foo; // "forward declaration" for a struct type

void OutputFoo(Foo & foo); // another "forward declaration", for a function

void OutputFooPointer(Foo * fooPointer) {
    // fooPointer->bar is unknown at this point...
    // we can still pass it by reference (not by value)
    OutputFoo(*fooPointer);
}

struct Foo { // actual definition of Foo
    int bar;
    Foo () : bar (10) {} 
};

void OutputFoo(Foo & foo) {
    // we can mention foo.bar here because it's after the actual definition
    std::cout << foo.bar;
}

int main() {
    Foo foo; // we can also instantiate after the definition (of course)
    OutputFooPointer(&foo);
}

…此外,“输出”通常被视为一个完整的单词,而不是两个完整的单词。”

您是否包括了
?包括fstream解决了我的问题。谢谢
#include <iostream>

int main() {
    std::ofstream outFile("Log.txt");
}