我的代码的示例输入是:
{ 1, 2, 3, 4 }
我希望忽略大括号和逗号,并将数字读入数组。
我怎样才能做到这一点?
嗯,这可能有用:
// Ignore all characters up to and including the open curly bracket
cin.ignore(100000, '{');
// Read the numbers into an array
int my_array[4];
unsigned int array_index = 0;
cin >> my_array[array_index];
array_index++;
cin >> my_array[array_index];
array_index++;
cin >> my_array[array_index];
array_index++;
cin >> my_array[array_index];
// Ignore all characters up to and including the newline.
cin.ignore(1000000, '\n');
你可以使用for
循环读取数字。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)