gpt4 book ai didi

c++ - 为什么同时包含

转载 作者:行者123 更新时间:2023-11-28 00:54:54 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why do I need to include both the iostream and fstream headers to open a file

我写了这段代码:

#include <iostream>
int main()
{
std::ofstream file_out("file.txt");
file_out.close();

return 0;
}

std::ofstream<iostream> 中定义, 但编译此代码时出现以下错误:

error: variable 'std::ofstream file_out' has initializer but incomplete type

我发现如果我还包括 <fstream>错误消失,代码编译。为什么我要包括 <fstream>如果std::ofstream包含在 <iostream> 中?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com