所以我很坚持努力想通对阻止我我的显示程序的文本程序这个bug ..C++显示一个文本文件......(“回声”的文本文件)
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
ifstream infile;
ofstream offile;
char text[1024];
cout <<"Please enter the name of the file: \n";
cin >> text;
infile.open(text);
string scores; // this lines...
getline(infile, scores, '\0'); // is what I'm using...
cout << scores << endl; // to display the file...
string name1;
int name2;
string name3;
int name4;
infile >> name1;
infile >> name2;
infile >> name3;
infile >> name4;
cout << "these two individual with their age add are" << name2 + name4 <<endl;
// 23 + 27
//the result I get is a bunch of numbers...
return 0;
}
有什么办法清洁剂或简单的方法,我可以用来显示文件?
所有在互联网上的方法是很难理解或保留因 跟踪文件是循环开..
我想你键入文件名并显示文件 的程序文件将包含以下...
jack 23
smith 27
而且我现在需要我用上面的代码来获得从文件信息从文件中获取数据...
我通过这个
你可以调用那么这个功能,例如在你的main()函数来读取和显示文件'非常确定'std :: cout << infile.rdbuf();'会做到这一点。 – chris
这是功课吗? – jwiscarson
std :: cout << infile.rdbuf(); – Cris