だから、私は自分のプログラムのテキストを表示するのを妨げているプログラムのこのバグを理解しようとして本当に行き詰まっています..
#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
また、ファイルからデータを取得する必要があります。上記のコードを使用して、ファイルからその情報を取得しています...