-3
基本上,我只需要在矢量所有的字母填寫的字符串。該向量是char類型的,但它不應該是正確的?當我調試它時,它表示字符串的大小仍然是0?這是一段代碼。麻煩向量轉換爲字符串
注:矢量大小爲7(在輸出測試),因此似乎問題並不在於載體中。
vector<char> final; //note this gets filled before reaching the loop
// fills vector in here, size is now 7
string* complete;
complete = new string[final.size()]; //set size of string to vector size
//debugger says size of complete is 0????
for (int i = 0; i < final.size(); i++) {
complete[i] = final[i]; //should fill string
}
cout << "COMPLETE:" << *complete << endl; //one letter output
你初始化'complete'到'string's的數組。 – bejado
'complete = new string [final.size()]'你在這裏創建一個字符串數組。你想要做的是:而不是使用指針,只需簡單的'std :: string'。很確定'std :: string complete(final.data())'會做詭計 – Fureeish
哦!你完全正確!感謝您指出了這一點! –