【发布时间】:2017-10-17 05:50:27
【问题描述】:
我正在尝试读取一个字符串,直到到达一个 ',' 字符并将读取的内容存储在一个新字符串中。
例如"5,6"
// Initialise variables.
string coorPair, xCoor, yCoor
// Ask to enter coordinates.
cout << "Input coordinates: ";
// Store coordinates.
cin >> coorPair
// Break coordinates into x and y variables and convert to integers.
// ?
我还需要将 y 值存储在单独的变量中。
在 C++ 中最好的方法是什么?
另外,验证输入以转换为整数并测试值范围的最佳方法是什么?
【问题讨论】: