我试图接收一串像这样的点(2,4),(5,8),(12,7),(15.54,3.65)并将其分离为X数组和y数组,请帮助我仍试图这样的初学者,这是灾难性的将字符串分隔为x和y的数组
string polygons;
int i = 0;
int length = polygons.length();
string x[10000];
int index = 0;
int k = 0;
getline(cin, polygons);
for (i = 0; i < length; i++)
{
if (polygons[i] == '(')
{
k = polygons.substr(i + 1, 20).find_first_of(",");
x[index] = polygons.substr(i + 1, ((k + i) - (i + 1)));
index++;
}
}
int a = 0;
string y[10000];
int index2 = 0;
int c = 0;
for (a = 0; a < length; a++)
{
if (polygons.substr(a) == ",")
{
c = polygons.substr(a + 1, 20).find_first_of(")");
}
y[index2] = polygons.substr(a + 1, ((c + a) - (a + 1)));
index2++;
}
建议整理括号并提供[mcve] – user4581301
推荐:打破工作。 [使用'std :: string :: find'](http://en.cppreference.com/w/cpp/string/basic_string/find)来帮助找到'('和')'然后打印出来它们之间。一旦你有了这个工作,用['std :: stringstream'](http://en.cppreference.com/w/cpp/io/basic_stringstream)和'std :: getline'替换打印出来的代码来分割成过去在括号之间的数字并打印数字。当这一切都正常工作,你有一个号码对流,找到一个好方法来存储对。 – user4581301
谢谢你,我会试试这个 – Antonio