gpt4 book ai didi

编译源代码时找不到 C++ 标识符

转载 作者:太空宇宙 更新时间:2023-11-04 14:55:43 28 4
gpt4 key购买 nike

这是我的代码:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int userInput = -9999;
userInput = ReadNumber();
WriteAnswer(userInput);
system("pause");
return 0;
};

int ReadNumber ()
{
int liInput = -9999;
cin >> liInput;
return liInput;
};

void WriteAnswer(int data)
{
cout << data << endl;
};

当我尝试编译时,它说:

1>error C3861: 'ReadNumber': 找不到标识符

1>error C3861: 'WriteAnswer': 找不到标识符

为什么会出现上面的错误?以及如何解决这个问题?

谢谢

最佳答案

C++ 源代码从头到尾编译

当编译器执行到这一步时:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int userInput = -9999;
userInput = ReadNumber(); // <-- What is this?

这是真的 -- 没有证据表明 ReadNumber 存在。

在使用函数之前声明它们的存在。

int ReadNumber ();
void WriteAnswer(int data);

关于编译源代码时找不到 C++ 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15527621/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com