这就是我到目前为止所做的:我想从C++中读取文件中的单词,并且我只允许使用cstring库.这是我的一段代码
#include <cstring>
#include <fstream>
#include <stdio.h>
using namespace std;
int main(){
ifstream file;
char word[1];
file.open("p.txt");
while (!file.eof()){
file >> word;
cout << word << endl;
}
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,一次只读一个字.但我不明白这是如何工作的.任何大小的char数组怎么可能是char字[1]或char字[50]一次只读一个字而忽略空格.
而且我想将这些单词存储在动态数组中.我怎样才能做到这一点?任何指导将不胜感激?