2017-07-31 120 views
-3

這是我的代碼。編譯完成後,控制檯啓動,但立即崩潰,說名稱已經停止工作。警告:擴展初始化程序列表僅在-std = C++ 11或-std = gnu ++ 11時可用。 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\編譯時C++程序崩潰

#include<iostream> 
#include<conio.h> 
#include<string> //introducing string classes. 
struct cia 
{ 
    std::string name; 
    std::string code; 
    float balance; 
}; 




int main() 
{ 
    using namespace std; 

    cia agent[10] = 
    { 

    agent[0] = 
    { "wallflower", 
     "007860", 
     300000 
    }, 

    agent[1] = 
    { 
     "albus", 
     "117861", 
     310000 
    }, 

    agent[2] = 
    { 
     "severus", 
     "227862", 
     600000 
    }, 

    agent[3] = 
    { 
     "enigma", 
     "337862", 
     550000 
    }, 


    }; 

    string head="\n\t\t\t\t\tCIA"; 
    string username; 
    string pass; 


    cout<<head; 
    cout<<"\n Welcome To The Most Secure network of Justice."; 
    cout<<"Username-; "; 
    cin>>username; 
    getch(); 


} 
+5

程序崩潰只有* *後,他們已經被編譯。在編譯之前,它們不能運行,所以它們不能崩潰。 –

+0

是的,但在編譯之後,它立即停止。我的意思是說控制檯(CMD)崩潰。 –

+0

你是如何編譯程序的?你的編譯器命令行是什麼樣的?你在使用什麼編譯器(以及哪個版本)? –

回答

0

代理的定義是錯誤的。你應該使用類似:

cia agent[4]; 
    agent[0] = 
    { "wallflower", 
     "007860", 
     300000 
    }; 

    agent[1] = 
    { 
     "albus", 
     "117861", 
     310000 
    }; 

    agent[2] = 
    { 
     "severus", 
     "227862", 
     600000 
    }; 

    agent[3] = 
    { 
     "enigma", 
     "337862", 
     550000 
    }; 
0

我覺得結構應該是這樣的:

cia agent[10] = { 
    {"wallflower", "007860, 300000}, 
    {"albus", "117861", 310000}, 
    ... and so on 
};