【发布时间】:2018-03-25 05:24:41
【问题描述】:
我有这个sn-p:
printf("\nEnter number of elements: ", MAX);
scanf("%d", &num);
printf("\nEnter %d Elements : ", num);
for (i = 0; i < num; i++)
scanf("%d", &arr[i]);
我想在arr[i] 中输入 1000 个整数,但是如果不手动输入 1000 个数字,我该怎么做呢?我正在考虑使用外部文件来存储数字,我只是在那里阅读,但我不知道如何......
【问题讨论】:
-
看起来你对 C 比对 C++ 更感兴趣。坚持使用 C,不要忘记检查来自
scanf的返回值,以确保您确实阅读了一些内容。 Also look intofscanfto read from files. -
我很灵活,我交替使用 C 和 C++
-
在 C++ 中,you would use a
std::ifstream与std::cin几乎相同 -
输入重定向,例如
./myprogram <mydata.txt
标签: c