このようにフォーマットされたデータファイルから読み取る必要があります
abcd(文字列) 1(整数) 2(整数) 3(整数)
abcde(文字列) 4(整数) 3(整数) 2(整数)
.
.
.
同じ行でのみ変数を使用するいくつかの機能を実行したいと考えています。しかし、ここに私のコードがあります。初心者なので訂正よろしくお願いします。
.h ファイル内
#include <string>
using namespace std;
#ifndef CALC_H
#define CALC_H
class Calc
{
public:
void readFile(string file);
private:
string name;
int a;
int b;
int c;
};
#endif
実装ファイルで
#include "Vehicle.h"
#include iostream>
#include fstream>
#include string>
#include cstdlib>
#include cmath>
using namespace std;
void Vehicle::readFile(string filename)
{
ifstream myIn;
int totalNum=0;
myIn.open(filename.c_str());
if (!myIn)
{
cerr<<"Data file failed to open!\n";
exit (0);
}
for (int i=0; i<MAX; i++)
{
while (myIn.peek() != EOF)
{
myIn>>calc[i].name;
myIn>>calc[i].a;
myIn>>calc[i].b;
myIn>>calc[i].c;
totalNum++;
}
}
myIN.close();
そして、ファイルから読み取ったものを表示したい
for (int i = 0; i < MAX; i++)
cout << calc[i].name << calc[i].a << calc[i].b << calc[i].c << endl;
申し訳ありませんが、私が正しい道を進んでいるかどうかを知りたいだけです。ありがとう