小编qwa*_*was的帖子

为什么char [1]从我的输入文件中读取整个单词?

这就是我到目前为止所做的:我想从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]一次只读一个字而忽略空格.

而且我想将这些单词存储在动态数组中.我怎样才能做到这一点?任何指导将不胜感激?

c++ arrays file

0
推荐指数
1
解决办法
552
查看次数

标签 统计

arrays ×1

c++ ×1

file ×1