Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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++ 在写入文件之前,如何检查文件是否为空?塔克斯_C++_File Handling - Fatal编程技术网

C++ 在写入文件之前,如何检查文件是否为空?塔克斯

C++ 在写入文件之前,如何检查文件是否为空?塔克斯,c++,file-handling,C++,File Handling,在将一些数据写入文件之前,我想检查该文件是否为空。如果它是空的,那么我 必须写一个0值的矩阵。那么,请告诉我怎么做 void details(int arr[][10])//假设此矩阵已包含0 //价值观 { int m1=10; int n1=10; 流式流量计; fout.open(“bookingb1.text”,ios::out); //这是我想查的。 无序地图; cout函数tellg()返回文件的读取(get)位置,我们使用std::ios::ate打开文件,文件的读取(get)位置

在将一些数据写入文件之前,我想检查该文件是否为空。如果它是空的,那么我 必须写一个0值的矩阵。那么,请告诉我怎么做

void details(int arr[][10])//假设此矩阵已包含0
//价值观
{
int m1=10;
int n1=10;
流式流量计;
fout.open(“bookingb1.text”,ios::out);
//这是我想查的。
无序地图;

cout函数
tellg()
返回文件的读取(get)位置,我们使用
std::ios::ate
打开文件,文件的读取(get)位置位于末尾。因此,如果
tellg()
返回0,它必须为空。

这回答了您的问题吗?这个ans不工作,您可以编写代码吗