#include <iostream> #include <fstream> using namespace std; int main() { ifstream obj; obj.open("a.txt"); char i; obj.read((char *)&i, 1); cout << i; obj.close(); return 0; }
使用>>运算符读取文件和使用c中的读取函数有什么区别?
read()函数读取给定数量的字符,而operator>>()读取格式和数据解释 .
例如:
char buf[11]; cin.read(buf, 10); buf[10] = 0; int a; cin >> a;
使用给定的输入 12345678901234567890 ,结果是
12345678901234567890
strcmp(buf, "1234567890") == 0 a == 1234567890
1 回答
read()函数读取给定数量的字符,而operator>>()读取格式和数据解释 .
例如:
使用给定的输入
12345678901234567890
,结果是