c++小白,求助。卡了贼久
读取名字的时候不能正确读取
#include <iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream in("d:\\worker.txt");
long worker_number;
char name[20];
int age;
double salary;
in >> worker_number;
int temp = 0; //temp记录读到的空格数量
for (int j = 0; j < 20; j++)
{
if (temp == 2)
break; //读到两个空格时停止
char c;
c = in.get();
name[j] = c;
if (c == ' ')
temp++;
}
cout << name << endl;
in >> age;
in >> salary;
system("pause");
}