開發平台(Platform): (Ex: Win10, Linux, ...)
win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
VC 2017
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
#pragma comment(lib,"Ws2_32.lib")
#include <Winsock2.h>
#include <Ws2tcpip.h>
#include <string>
#include <vector>
#include <map>
#include <mutex>
問題(Question):
vector 刪除元素時發生錯誤,最神奇的地方是:
vector 是有正確存放資料
想詢問有什麼特殊情況會發生這樣的事情呢?
且 iterator 也有正確指向資料
餵入的資料(Input):
struct ptr
預期的正確結果(Expected Output):
可以刪除元素
錯誤結果(Wrong Output):
擲回例外狀況
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
https://pastebin.com/W8eRsbef
補充說明(Supplement):
https://imgur.com/a/2ScWsfO
思考想法:
int main 選擇要擔任 server 或 client, 然後就 getchar() 等關閉.
希望能實現 non-blocking socket recv/ send/ accept
因此採用 thread 和 select 去避免無回應的情況
問題出在當 client 斷線後,我會收到 recv <= 0
那我就要將該 clinet listener 砍除
問題發生在砍除的時候 vector.erease
但砍除前都有抓到 iterator , 因此覺得奇怪