ofstream错误:error: variable ‘std::ofstream ofs’ has initializer but incomplete type

简介: ofstream错误:error: variable ‘std::ofstream ofs’ has initializer but incomplete type

在使用std::ofstream写文件时,编译器提示如下错误:

error: variable ‘std::ofstream ofs’ has initializer but incomplete type
         std::ofstream ofs(string(TMP_STATE_FILE));


这个错误上由于没有保护头文件导致的。


包含上头文件,编译通过。

 
#include<fstream> 
目录
相关文章
|
2月前
|
iOS开发
解决Invalid `Podfile` file: no implicit conversion of nil into String
解决Invalid `Podfile` file: no implicit conversion of nil into String
30 0
|
10月前
|
安全 C语言
警告 1 warning C4996: ‘scanf‘: This function or variable may be unsafe.
警告 1 warning C4996: ‘scanf‘: This function or variable may be unsafe.
成功解决absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'data_format'
成功解决absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'data_format'
error: possibly undefined macro: LT_SYS_SYMBOL_USCORE please use m4_pattern_allow
error: possibly undefined macro: LT_SYS_SYMBOL_USCORE please use m4_pattern_allow
137 0
error: implicit declaration of function ‘RAND_egd’ [-Werror=implicit-function-declaration]
error: implicit declaration of function ‘RAND_egd’ [-Werror=implicit-function-declaration]
119 0
error: implicit declaration of function ‘read‘ [-Werror,-Wimplicit-function-declaration]
error: implicit declaration of function ‘read‘ [-Werror,-Wimplicit-function-declaration]
238 0
|
C语言
error: implicit declaration of function ‘VerifyFixClassname‘ is invalid in C99 [-Werror,-Wimplicit-f
error: implicit declaration of function ‘VerifyFixClassname‘ is invalid in C99 [-Werror,-Wimplicit-f
140 0
|
C++
warning C4996 sprintf This function or variable may be unsafe
warning C4996 sprintf This function or variable may be unsafe
80 0
解决办法:defined but not used [-Werror=unused-variable]
解决办法:defined but not used [-Werror=unused-variable]
749 0
|
安全
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误
275 0
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误