[問題] string::substr()丟出例外的可能情形
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEV C++ 5.4.1
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
大家好,想跟各位請教一下:
要做分割字串,想法是每讀完一行後用substr來指定需要的部分字串(資料上色部分),
並轉換成數字存入vector,編譯也沒問題,但在執行的時候只做完一部分便會跳出
terminate called after throwing an instance of std out of range
what() basic_string ::substr
上網有查到可能是substr()的index大過string的長度
但檢查後應該是沒有設錯,請問是哪邊的問題造成out of range?
字串長度都是10(用.size()測的),o0與0,0與0間都是一個空格
餵入的資料(Input):
o0 0 0 : N
o1 0 0 : N
o2 0 0 : N
o3 0 0 : N
(放在test3.pl裡)
預期的正確結果(Expected Output):
o0 0 0 : N
0,0
o1 0 0 : N
0,0
o2 0 0 : N
0,0
o3 0 0 : N
0,0
0:0
0:0
0:0
0:0
錯誤結果(Wrong Output):
o0 0 0 : N
0,0
o1 0 0 : N
0,0
o2 0 0 : N
0,0
o3 0 0 : N
0,0
terminate called after throwing an instance of std out of range
what() basic_string ::substr
this application has requested the runtime to terminate it in an unusual way
please contact the application's support team for more information
程式碼(Code):(請善用置底文網頁, 記得排版)
http://codepad.org/2OD6Infr
補充說明(Supplement):
--
║ ◥█ “ ,uzdyt' je to ndherné jmeno.” ║
║ ◢◤ ╚╣╠╝ ◢▄ 〒 ║
║ ╔╬╝ -_- 〒 〒 ║
║ ║﹎﹡ ﹎ ∕▇﹨ ﹎ ∥ 〒 ║
║ ﹎—║ ﹏ ﹎﹍/︱︱ ﹊ ﹊﹊╲ ∥ ║
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 36.229.31.32
→
06/06 23:02, , 1F
06/06 23:02, 1F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章