[英]Identifier not found and undeclared identifier
這是我使用的代碼,出於某種原因,它說有未聲明的標識符
#include <string>
#include <iostream>
#include "stdafx.h"
using namespace std;
int main()
{
bool Firstboot = true;
EntryPoint();
cout << "Hello World!" << endl;
return 0;
}
int MainMenu()
{
FormatedOut("MainMenu", "Menu1", "Menu1");
}
int Menu1()
{
FormatedOut("Menu1", "SubMenuOption1", "SubMenuOption1");
}
int EntryPoint() {
FormatedOut("MainMenu", "Menu1", "Menu1");
string option;
cin >> option;
if (option == "1")
{
Menu1();
}
}
int FormatedOut(string MenuName, string FirstOption, string FirstOptionTarget) {
cout << "----------------";
cout << "| " + MenuName;
cout << "|---------------";
cout << "| ";
cout << "| " + FirstOption;
EntryPoint();
}
我已經在Visual Studio 2017的C ++中對此進行了編碼
我在過去半個小時里遇到的錯誤
C3861 'EntryPoint': identifier not found 8
C2065 'cout': undeclared identifier 9
C2065 'endl': undeclared identifier 9
C3861 'FormatedOut': identifier not found 15
C3861 'FormatedOut': identifier not found 19
C3861 'FormatedOut': identifier not found 24
C2065 'string': undeclared identifier 26
C2065 'option': undeclared identifier 26
C2065 'cin': undeclared identifier 27
C2065 'option': undeclared identifier 27
C2065 'option': undeclared identifier 28
C2065 'string': undeclared identifier 34
您能給我的任何幫助將不勝感激
您需要為在源文件中調用后出現的函數編寫函數原型 。
即在main
之前,寫
int EntryPoint();
等等。 您可能還會發現stdafx.h
也必須是源文件的第一行,具體取決於您的編譯器設置(這是MSVC使用的預編譯頭的名稱)。
編譯器就像您一樣從上到下讀取。 當到達此行時: EntryPoint();
它從來沒有見過一個稱為入口點的功能,所以它抱怨。 您需要了解function prototyping
。
在使用之前將您的函數原型:
int EntryPoint();
...
int main()
{
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int EntryPoint();
int FormatedOut(string MenuName, string FirstOption, string FirstOptionTarget);
add this before main() it should work
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.