2013-02-22 43 views
0

這段代碼有什麼問題?爲什麼1 compilator說它確定並運行它,但來自微軟的其他人則大聲疾呼。我什至不能找到錯誤的錯誤的東西是錯誤的。DEV C++ compiless但Visual Studio不會

#include <iostream> 
#include <cstdlib> 
#include <ctime> 
#include <cstring> 
using namespace std; 
class Person 
{ 
private: 
    static const int LIMIT = 256; 
    string lname; 
    char fname[LIMIT]; 
public: 
    Person() { lname = "";fname[0] = '\0'; } 
    Person(const string & ln , const char* fn = "HejTy") { lname=ln; strncpy(fname,fn,LIMIT);} 
    void Show() const { cout << "nieformalnie: " << fname << " " << lname << endl; } 
    void FormalShow() const { cout << "formalnie: " << lname << " " << fname << endl; } 
}; 
int main(){ 
    Person one; 
    Person two("StaszeK"); 
    Person three("JACEK", "Placek"); 
    one.Show(); 
    cout << endl; 
    one.FormalShow(); 
    two.Show(); 
    cout << endl; 
    two.FormalShow(); 
    cout << endl; 
    three.Show(); 
    cout << endl; 
    three.FormalShow(); 
     cout << endl; 
    system("PAUSE"); 
    return 0; 
} 
+1

什麼是錯誤信息? – Mahesh 2013-02-22 19:56:37

+0

「我甚至都找不到錯誤的錯誤。」忽略999999999最後一行錯誤消息。第一個總是重要的一個。因爲這是編譯器第一次遇到。以下可能是廢話取決於該錯誤。 – stefan 2013-02-22 20:03:55

+0

Dev C++使用與最新C++標準不兼容的舊版本的MinGW編譯器,我建議您將IDE更改爲任何較新版本(例如Code :: Blocks使用較新的MinGW)。 – micnyk 2013-02-22 20:07:55

回答

1

您缺少標頭<string>。包括它。

#include <string> 
+0

我認爲我相同像但功能更多。 dev C++怎麼可能不爲此而大喊大叫?無論如何thx兄弟現在工作。 – 2013-02-22 20:03:18

+0

@FilipBartuzi DevC++做所有類型的奇怪的東西,它根本不應該被使用 – stefan 2013-02-22 20:04:33

+0

@FilipBartuzi:''是C風格的字符串函數的C++等價物,例如'strcat','strdup'和'strcpy'。 – 2013-02-22 20:40:44