如何將字符串「Ac milan」和「Real Madryt」與空格分隔開來?C++,如何標記這個字符串?
這裏是我的嘗試:
string linia = "Ac milan ; Real Madryt ; 0 ; 2";
str = new char [linia.size()+1];
strcpy(str, linia.c_str());
sscanf(str, "%s ; %s ; %d ; %d", a, b, &c, &d);
,但它不工作;我有:a= Ac;
b = (null); c=0; d=2;
看到我的解決方案:標記化一串數據轉化爲結構向量?](http://stackoverflow.com/questions/5462022/tokenizing-a-string-of-data-into-a-vector-of-structs/5462907#5462907) – Nawaz 2011-03-31 15:41:25
個人,我偏愛自己的解決方案。 :) http://stackoverflow.com/questions/3046747/c-stl-selective-iterator/3047106#3047106 – 2011-03-31 15:42:49
順便說一下,這是皇馬,不是真正的馬德里:) – 2011-03-31 15:51:13