我已經寫了一個小程序:複製數組到載體
void showrecord()
{
char *a[]={ "O_BILLABLE_ACCOUNT","O_CUSTOMER_TYPE_INDICATOR",
"O_A_PARTY_MSISDN_ID","O_A_PARTY_EQUIPMENT_NUMBER",
"O_A_PARTY_IMSI","O_A_PARTY_LOCATION_INFO_CELL_ID",
...
};
vector<std::string> fields(a,a+75);
cout<<"done!!!"<<endl;
}
int main()
{
showrecord();
}
我有字符串文字的陣列,我想他們被複制到載體中。 我沒有找到任何其他簡單的方法來做到這一點:(或者,如果有任何直接的方式來初始化矢量而不使用數組,這將是非常有幫助的 這是在我運行可執行文件後轉儲核心。UNIX 它給了我就像一個警告,但:
Warning 829: "test.cpp", line 12
# Implicit conversion of string literal to 'char *' is deprecated.
D_TYPE","O_VARCHAR_5","O_VARCHAR_6","O_VARCHAR_7","O_VARCHAR_8","O_VARCHAR_9"};
但相同的代碼運行良好的窗口,沒有任何問題 我使用HPUX編譯ACC
請幫助 。!編輯 下面是堆轉儲的堆棧跟蹤。
(gdb) where
#0 0x6800ad94 in strlen+0xc() from /usr/lib/libc.2
#1 0xabc0 in std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string<char,std::char_traits<char>,std::allocator<char>>+0x20()
#2 0xae9c in std<char const **,std::basic_string<char,std::char_traits<char>,std::allocator<char>> *,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>::uninitialized_copy+0x60()
#3 0x9ccc in _C_init_aux__Q2_3std6vectorXTQ2_3std12basic_stringXTcTQ2_3std11char_traitsXTc_TQ2_3std9allocatorXTc__TQ2_3std9allocatorXTQ2_3std12basic_stringXTcTQ2_3std11char_traitsXTc_TQ2_3std9allocatorXTc____XTPPCc_FPPCcT118_RW_is_not_integer+0x2d8
()
#4 0x9624 in showrecord() at test.cpp:13
#5 0xdbd8 in main() at test.cpp:21
這是什麼'uninitialized_copy'的堆棧跟蹤?你是否在展示導致這次事故的競爭計劃?另外,我會在gcc中嘗試這個,如果它工作的比你可能在aCC上有問題(這是非常古老的,不是嗎?HPUX正在逐步淘汰AFAIK) – davka 2011-06-14 11:39:53
@davka:這是一個庫的實現細節,I在STL實現中已經看到具有該名稱的函數將構造從一組迭代器複製到某些未初始化的內存中。 – 2011-06-14 12:00:48
@davka'uninitialized_copy'可能是由'std :: vector'的構造函數調用的。 – 2011-06-14 12:02:29