很多题都会要求读取txt作为输入。
fstream
ifstream inputData("/cpp/input.txt");
if (!inputData.is_open())
{
cout << "open failed" << endl;
}
...
inputData.close();
string temp;
getline(inputData, temp);
char a[65];
strcpy(a, temp.c_str());//temp是string类型,需要转换成const char*
char *w = strtok(a, " ");//第一个参数char*,第二个参数是分隔符
char *h = strtok(NULL, " ");//第一次以后,第一个参数传NULL即可获取下一段字符串
//如果内容是数字,atoi(w)与atoi(h)可将char*转换成int