我的问题是我已经定义了一个这样的字符串:
string messages = "This is an option; This is a really long option; Another One For Testing Sake; This is the last one I swear; You lied to me!";
这 ';' 字符串中的字符将被视为分隔符。在事物的宏伟计划中,这个字符串被调用到一个函数res.addMessages(messages);
中,其代码是:
void ConflictResMenu::addMessages(string messages) {
int idx = 0;
for (int i = 0; i < messages.length(); i++) {
cout << messages.find_first_of(';') << endl;
if (messages[i] == this->delim) {
this->split_messages.push_back(messages.substr(idx, i));
idx = i + 1;
}
}
}
这样做的问题是 if 子句在所有错误的时间被调用,所以输出结果如下:
This is an option
This is a really long option; Another One For
Another One For Testing Sake; This is the last one I swear; You lied to me!
This is the last one I swear; You lied to me!
老实说,我不知道这里发生了什么。如果有人可以提供帮助或提出更好的解决方法,我将不胜感激。