input(時間と価格)が次のようになっているファイルを読み取ろうとしています。時間、分、秒の値を保持する12:23:31
67 12:31:23 78 [...]
を作成しました。struct
以前strtok
は、個々の値をトークン化し、atof
それらを保存するために使用していました。ただし、時間をトークン化しようとするとエラーが発生します:変換できませんstd::string' to 'char*' for argument 1 to 'char*'
struct time
{
int hours;
int minutes;
int seconds;
double price;
};
int main()
{
string file, input;
time* time_array;
char* tok;
cout << "Enter a file name to read input: ";
cin >> file;
ifstream file_name(file.c_str());
file_name >> input;
file_name >> input;
//while(!file_name.eof())
for(int i = 0; i < 4; i++)
{
time_array = new time;
file_name >> input;
tok = strtok(input, ":"); //ERROR HERE
while(tok != NULL)
{
*time_array.hours = atof(tok[0]);
*time_array.minutes = atof(tok[1]);
*time_array.seconds = atof(tok[2]);
}
file_name >> input;
*time_array.prine = atof(input);
}
}