c++ 读写文件出错
判断一个文件存在不存在?
如果不存在,写进一个数字1
如果存在,读出数字,加一后再存入,直到读出的数字为100,执行test()函数。
下面的代码可以写1进去,但是读出后就变成一串数字?
#include "iostream.h"
#include "fstream.h"
using namespace std;
#define NUM_FILE "D:\\test.txt"
int main()
{
int i;
ifstream r_file(NUM_FILE, ios::binary);
if(!r_file)
{
r_file.close();
ofstream w_file(NUM_FILE, ios::binary);
w_file << 1;
w_file.close();
}
else
{
cout << r_file.get();
i << r_file.get();
cout << i;
}
system("pause");
return(0);
}
如果不存在,写进一个数字1
如果存在,读出数字,加一后再存入,直到读出的数字为100,执行test()函数。
下面的代码可以写1进去,但是读出后就变成一串数字?
#include "iostream.h"
#include "fstream.h"
using namespace std;
#define NUM_FILE "D:\\test.txt"
int main()
{
int i;
ifstream r_file(NUM_FILE, ios::binary);
if(!r_file)
{
r_file.close();
ofstream w_file(NUM_FILE, ios::binary);
w_file << 1;
w_file.close();
}
else
{
cout << r_file.get();
i << r_file.get();
cout << i;
}
system("pause");
return(0);
}
...全文
相关推荐
C/C++读写文本文件、二进制文件的方法
最后,我们使用fclose函数关闭文件。三、掌握CPP文本文件读写方式CPP语言中读写文本文件与C语言类似,但是CPP语言提供了更多的功能和更好的性能。
usart_test.rar_cpp 串口_串口 CPP
**错误处理**:串口通信过程中可能会遇到各种错误,如打开串口失败、读写数据出错等。因此,编写串口程序时需要加入适当的错误处理代码。5.
FI_C++_
类,用于读写文件。
C++课程设计综合题目.zip
**文件操作**:C++提供了标准库中的`fstream`来处理文件读写。了解如何打开、读取、写入和关闭文件至关重要,这对于处理ELF这样的二进制文件尤其重要。3.
C++读写.mat文件的方法
通过上述介绍和代码示例,我们可以看到,在C++中读写.mat文件并不是一个特别复杂的过程。


