【发布时间】:2015-03-26 23:00:47
【问题描述】:
大家好,我一直在做一个任务,我要求编写一个列出文件内容的程序。
#include<iostream>
#include<fstream>
using namespace std;
int main() {
string array[5];
ifstream infile("file_names.txt");
int x=0;
while(infile>>array[x++]){
for(int i=0;i<=x;i++){
infile >> array[i];
cout << array[i] << endl;}}
}
基本上我有一个名为“file_names.txt”的文件,其中包含三个字符串,我希望我的程序列出它们。
【问题讨论】:
-
您尝试了 A,预期 B,并观察了 C。描述 A、B 和 C
-
“我卡住了”具体在哪一点?
-
如果你只想列出一些字符串,你不需要嵌套循环,也不需要数组。
标签: c++ arrays loops for-loop while-loop