2016-05-11 44 views
0

我在聲明字符串時遇到問題。有關在arduino中聲明字符串的問題

Arduino: 1.6.9 (Windows 10), Board: "Arduino/Genuino Uno"

readBinaryCode:3: error: 'string' does not name a type

string code = "10101010010010100101000101010101111100" 

C:\Users\Jerel\Desktop\All\Sketchs\readBinaryCode\readBinaryCode.ino: In function 'void loop()':

readBinaryCode:12: error: 'code' was not declared in this scope

for(int i = 0; i < code.length(); i++) {... 

exit status 1

'string' does not name a type

該報告將有「編譯過程中顯示詳細輸出」與 更多信息在文件中啓用 選項 - >首選項。

+0

嘗試'的std :: string'。我今天已經做過Zuul笑話了。並確保包含「」。 – user4581301

+0

可能重複的[怪異字符串不會命名一個類型錯誤C + +](http://stackoverflow.com/questions/5527665/weird-string-does-not-name-a-type-error-c) – user4581301

回答

0

它告訴你真相。

'string' does not name a type 

而不是

`string code` use `String code` 



void setup() { 
     // put your setup code here, to run once: 
    String code = "10101010010010100101000101010101111100"; 

    } 

更新 我們不需要任何包含任何該

+0

我非常懷疑你在暗示什麼。 'string.h'是一個包含'strcpy'的C標準庫頭。'string'是'string'的C++類模板。我沒有在Arduino上編程,但是如果他們劫持了一個C庫頭文件,並開始使用複製了C++的類來填充它,我會感到驚訝。 –

+0

我得到了。我們不需要包含聲明。是的,你對string.h是正確的。我的錯。 – Ccr