[問題] C++ string 的擷取...

看板C_and_CPP (C/C++)作者 (GO!!!!!!!)時間15年前 (2010/07/27 21:03), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
遇到的問題: (題意請描述清楚) String^ infile; String^ line; String^ tem; int L,P; openFileDialog1->Title = "開啟一個點資料檔"; openFileDialog1->Filter = "(*.txt)|*.txt|All files (*.*)|*.*"; if(openFileDialog1->ShowDialog() != System::Windows::Forms::DialogResult::OK) return; infile = openFileDialog1->FileName; FileStream^ fs = gcnew FileStream(infile,FileMode::Open ); StreamReader^ sr = gcnew StreamReader(fs); line = sr->ReadLine(); L = Convert::ToInt16( line->Substring(0,line->IndexOf(" "))); P = Convert::ToInt16( line->Substring(0,line->IndexOf(" "))); 我開的txt檔,line讀出來的第一條為"1 4",以上程式碼沒有錯,只是L =P =1 而P我是希望可以抓到為4 因為是String 所以我查過mdsn的string成員我找到 substring 以及indexOf來用 但沒辦法用 strtok 這個要讀char~~~ 希望得到的正確結果: 希望L=1 P=4 程式跑出來的錯誤結果: 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux) VC++ 2008 有問題的code: (請善用置底文標色功能) 補充說明: C++新手,大家拜託幫忙一下 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.171.61.43

07/27 21:10, , 1F
String.Split
07/27 21:10, 1F

07/28 03:07, , 2F
猜的 Convert::ToInt16( line->Substring(
07/28 03:07, 2F

07/28 03:08, , 3F
line->IndexOf(" "),line->IndexOf("\n")));
07/28 03:08, 3F
文章代碼(AID): #1CJjaBz1 (C_and_CPP)
文章代碼(AID): #1CJjaBz1 (C_and_CPP)