[問題] strtok v.s getline 切割
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
我想請問一下如果只是想針對一行座標去做切割
要用strtok 還是getline比較快?
餵入的資料(Input):
(2,3,1)(2,4,1)(4,4,1)(4,3,1)
預期的正確結果(Expected Output):
(int)2 3 1 2 4 1 4 4 1 4 3 1
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
getline(file,str);
stringstream ss(str);
string sub_str;
while(getline(ss,sub_str,','))
{
//cout <<"initial="<< sub_str << endl;
stringstream ss2(sub_str);
string sub_str2;
while(getline(ss2,sub_str2,'('))
{
stringstream ss3(sub_str2);
string sub_str3;
while(getline(ss3,sub_str3,')'))
{
//cout << sub_str3 << endl;
if(sub_str3!=" ")
{
int i=atoi(sub_str3.c_str());
//cout<<"i="<<i<<endl;
}
}
}
}
補充說明(Supplement):
感覺上用getline內建的指令要切割三次,是否改成strtok比較快?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.216.118
※ 編輯: justin719 來自: 140.116.216.118 (12/08 22:15)
→
12/08 22:16, , 1F
12/08 22:16, 1F
→
12/08 22:17, , 2F
12/08 22:17, 2F
→
12/08 22:18, , 3F
12/08 22:18, 3F
→
12/08 22:19, , 4F
12/08 22:19, 4F
→
12/09 16:28, , 5F
12/09 16:28, 5F