0
我正在使用C++使用分隔符標記字符串,並且可以在while循環中使用cout輸出當前標記。我想要做的是將令牌的當前值存儲在一個數組中,以便稍後可以訪問它。下面是代碼我現在有:將字符串標記存儲到數組中
string s = "Test>=Test>=Test";
string delimiter = ">=";
vector<string> Log;
int Count = 0;
size_t pos = 0;
string token;
while ((pos = s.find(delimiter)) != string::npos) {
token = s.substr(0, pos);
strcpy(Log[Count].c_str(), token.c_str());
Count++;
s.erase(0, pos + delimiter.length());
}
當然,這不會編譯。如何將'strcpy()'放入'c_str()'調用的結果中?您應該簡單地將該標記push_back()到Log中。 –