简体   繁体   English

缺少函数标头C ++

[英]Missing function header C++

i am getting this error when i want to build my cpp file. 当我要构建我的cpp文件时出现此错误。

Severity Code Description Project File Line Suppression State Error C2447 '{': missing function header (old-style formal list?) Win32Project1 d:\\persoonlijk\\documenten\\2e leerjaar\\c++\\win32project1\\win32project1\\leerlinggegevens_hfst3.cpp 2 严重性代码说明项目文件行抑制状态错误C2447'{':缺少函数头(旧式的正式列表?)Win32Project1 d:\\ persoonlijk \\ documenten \\ 2e leerjaar \\ c ++ \\ win32project1 \\ win32project1 \\ leerlinggegevens_hfst3.cpp 2

Here is the code i am using: 这是我正在使用的代码:

/*Hoofdstuk 3, Leerlinggegevens*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int lnr;
    string lnm;
    string oplnm;
    string klasm;
    //DECRALEREN

    cout << "Voer je leerlingnummer in: \n";
    cin >> lnr;


    cout << "Vul je naam in: \n";
    cin >> lnm;

    cout << "Vul je opleiding in: \n";
    cin >> oplnm;

    cout << "Vul je klas in: \n";
    cin >> klasm;

    cout << "Jouw ingevulde leerleerlinggegevens bestaan uit: \n" << "Leerling " << lnr << " met leerlingnummer " << lnm << "staat ingeschreven bij opleiding " << oplnm << " \n" << "Leerlingnummer " << lnr << " zit in klas " << klasm << endl;


    system("PAUSE");

}

Thanks for your time! 谢谢你的时间!

Your code works fine in Windows environment it seems. 您的代码似乎可以在Windows环境中正常工作。

In case you are running on Linux environment, but I am not quite sure whether system("PAUSE"); 如果您在Linux环境上运行,但是我不太确定是否system("PAUSE"); works over there or not. 是否在那儿工作。 Even, this seems to me as non - portable code. 即使在我看来,这也是非便携式代码。

I would recommend you to use cin.get() or getchar() instead, to make it portable. 我建议您改用cin.get()getchar()使其可移植。 If you want to more why I am saying so, you can go through this link: http://www.gidnetwork.com/b-61.html 如果您想了解我为什么这么说,可以通过以下链接进行访问: http : //www.gidnetwork.com/b-61.html

The source code you posted compiles just fine with both Microsoft Visual C++ 2015 and gcc (tried on ideone.com). 您发布的源代码可以与Microsoft Visual C ++ 2015和gcc一起编译(在ideone.com上进行了尝试)。

The only way to get the C2447 compile error you are getting, with Visual C++, is to add a semi-colon (;) right after main(): 使用Visual C ++获得C2447编译错误的唯一方法是在main()之后添加分号(;):

int main(); int main();
{ {

(but Visual Studio 2015 editor highlights the error, even before compiling the code). (但即使在编译代码之前,Visual Studio 2015编辑器也会突出显示该错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM