[問題] struct&string問題
最近在寫二元搜尋樹
有一個bug百思不得其解
下面是每個node的struct
typedef struct student
{
unsigned int sid;
unsigned int score;
struct student*llink,*rlink;
string name;
}NodeType;
在insert一個node之後 發現樹的走訪一直有問題
後來發現是name的問題
NodeType student;
student.rlink=NULL;
student.llink=NULL;
cin>>student.name;
cout<<student.name; <--正常
BST.Insert(&student); <--Insert的最後一行也有印出正常的name
cout<<BST.root->score<<BST.root->name;(因為只有一個,就用root去讀了..)
score數值正常,後面就overflow了...測過length()高達2萬多...
把string換成char name[50]就正常了,50是隨意打的,測資的name只有打abc...
不知道問題出在哪裡?
編譯器是dev c++
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.39.182.199
※ 編輯: jeffreyshe 來自: 114.39.182.199 (04/21 06:09)
※ 編輯: jeffreyshe 來自: 114.39.182.199 (04/21 06:18)
→
04/21 06:21, , 1F
04/21 06:21, 1F
→
04/21 07:56, , 2F
04/21 07:56, 2F
推
04/21 09:42, , 3F
04/21 09:42, 3F
推
05/02 15:20, , 4F
05/02 15:20, 4F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):