use*_*967 7 c++ string file char
我试着这样做
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char b[2];
ifstream f("prad.txt");
f>>b ;
cout <<b;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它应该读取2个字符,但它读取整行.这适用于另一种语言但由于某种原因无法在C++中运行.
您可以使用read()指定要读取的字符数:
char b[3] = "";
ifstream f("prad.txt");
f.read(b, sizeof(b) - 1); // Read one less that sizeof(b) to ensure null
cout << b; // terminated for use with cout.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16580 次 |
| 最近记录: |