2015-04-15 70 views
1

我有包含1或0的數組。我想追加它併成爲一個線串。目前我失敗了。這是我的代碼。請幫忙,因爲我無法完成它。每次我加載的最終結果到控制檯,僅笑臉而不是1或0。請幫助如何將數組中的數據轉換爲字符串C++

int pixelValueArray[256]; 
String testing; 

for(int d=0;d<256;d++) 
{ 
    testing.append(1,pixelValueArray[d]); 
} 

cout<<testing; 
+0

ASCII碼字符「0」是48而不是寫'數量48',它寫的更自我是一個好主意記錄「0」。 –

+0

嗨,其實我想在opencv中使用我的ANN的字符串。該字符串必須轉換爲此cv :: Mat數據(1,ATTRIBUTES,CV_32F)。有什麼辦法可以將數組內的數據轉換爲MAT數據? –

回答

1

整數數字的ASCII值由'0' + digit給出。

for(int i = 0; i < 256; i++) 
    testing.append(1, '0' + pixelValueArray[i]); 

或者你可以使用簡單的+=

for(int i = 0; i < 256; i++) 
    testing += '0' + pixelValueArray[i]; 
+0

非常感謝...順便說一句,我用字符串轉換爲MAT,但通過使用這個錯誤得到了...你有沒有想過這個? –

+0

對(INT d = 0; d <256; d ++) \t \t { \t \t \t測試+ = '0' + pixelValueArray [d]; \t \t} \t \t cout << testing; //這是字符串 \t \t \t \t cv :: Mat data(1,ATTRIBUTES,CV_32F,testing.data()); –

相關問題