5
我有我想要在我的應用程序上實現的一個步驟的示例程序。我想分別將字符串的int元素push_back到一個向量中。我怎麼能夠?從字符串到字符串流到矢量<int>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(){
string line = "1 2 3 4 5"; //includes spaces
stringstream lineStream(line);
vector<int> numbers; // how do I push_back the numbers (separately) here?
// in this example I know the size of my string but in my application I won't
}
這是一個完美的例子,用於C++最新的錯誤。在幾乎所有其他語言中,這將是對''的分割,然後是每個元素的.toInt()。相反,我們正在應用一系列非常複雜的模板化算法。 – dicroce 2009-01-18 17:39:49