c++ - DEV C++ 编译但 Visual Studio 不

标签 c++ visual-studio-2010 dev-c++

这段代码有什么问题?为什么 1 个编译器说它可以并运行它,但来自 Microsoft 的其他编译器却大喊大叫错误。我什至找不到错误的地方,因为有数十亿行错误。

    #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;
}

最佳答案

您缺少标题 <string> .包括它。

#include <string>

关于c++ - DEV C++ 编译但 Visual Studio 不,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15032222/

相关文章:

c++ - x86 上的竞争条件

c# - VSTO 开发 - VS2010/.NET 4.0 中的主要改进?

c# - 基于自定义模型创建强类型 View

c - Dev C 不断返回错误值

c++ - 无法从 <brace-enclosed initializer list> 转换

android - 共享指针 : are there any gotcha differences between Android's "sp<>" template and BOOST's "shared_ptr<>" template?

visual-studio-2010 - MSBuild.Community.Tasks 和 Zip,设置 zip 文件夹结构

C - 将文本读入字符数组并打印问题

c++ - 如何在dev C++中创建头文件

c++ - 无法在C++中使用相同的fstream对象进行读写