2017-06-06 98 views
-5

嘿人們瀏覽stackoverflow,我正在嘗試爲我的NodeMCU板構建一個大程序,我需要幾個結構,但是我無法在這個小示例中使用它:Arduino IDE中的結構不起作用

struct Accounts{ 
String username; 
String password; 
int ip; 
}; 


void setup() { 
// put your setup code here, to run once: 
Serial.begin(115200); 

struct Accounts Random;// = {"Random", "This", 192614}; 

} 

void loop() { 
    // put your main code here, to run repeatedly: 
    if(struct Accounts Random.username != Null){ 
    Serial.print("Worked"); 
    } 
} 

運行這個程序我得到的錯誤代碼:預期的主要表達式在'結構'之前。誰能幫我嗎?我已經嘗試使用typedef結構。

+0

歡迎來到Stack Overflow。請花些時間閱讀[The Tour](http://stackoverflow.com/tour),並參閱[幫助中心](http://stackoverflow.com/help/asking)中的資料,瞭解您可以在這裏問。 –

+1

通過試驗和錯誤學習C++是一個非常糟糕的主意。您應該從[此列表]中獲得一本書(http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)以瞭解基本知識。 –

回答

0
if(struct Accounts Random.username != Null){ 

您正在將一個聲明放入if表達式中。刪除struct Accounts,以便只有變量名稱在那裏。

if(Random.username != Null){ 

此外,您定義Randomsetup功能裏面,所以它不是可見的loop功能。你需要在函數之外定義它。

struct Accounts Random;// = {"Random", "This", 192614}; 

void setup() { 
    // put your setup code here, to run once: 
    Serial.begin(115200); 

}