简单的计算器应该需要2秒钟来修复它的10行
Simple calculator should take 2 seconds to fix its like 10 lines
试图制作一个简单的计算器,但我甚至无法让我的第一个函数工作。我一直在努力让我的头和.cpp尽可能地有条理,因为我记得以前这些都很重要。哈哈。我的印象是头文件包含在main.cpp中,它有头保护。这些只是我函数的声明,对吗?然后,Calculation的sFunctions.cpp就是我为上一个在头文件中创建的声明函数编写代码的地方。我也不确定什么时候应该包括iostream和stdafx.h等等。无论如何,提前感谢你们的帮助,这是我的3个文件,我现在只想从用户那里得到一个整数。
Calculator.cpp
#include "stdafx.h"
#include <iostream>
#include "CalculatorDeclarations.h"
int main()
{
int getFirstInteger(int userInput)
return 0;
}
CalculatorDeclarations.h
#ifndef ADD_H
#define ADD_H
#include "stdafx.h"
#include <iostream>
int getFirstInteger();
#endif
CalculationsFunctions.cpp
#include "stdafx.h"
#include <iostream>
int getFirstInteger(int userInput)
{
std::cout << "Please enter the first integer you would like to use." << std::endl;
std::cin >> userInput;
return userInput;
}
错误:
Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) ConsoleApplication1 c:UsersShanedocumentsvisual studio 2015ProjectsConsoleApplication1ConsoleApplication1MSVCRTD.lib(exe_main.obj) 1
Error LNK1120 1 unresolved externals ConsoleApplication1 c:usersshanedocumentsvisual studio 2015ProjectsConsoleApplication1DebugConsoleApplication1.exe 1
好吧,你的第一个问题是你的"主要"方法
int main()
{
int getFirstInteger(int userInput)
return 0;
}
语法不正确(应以分号结尾)。你应该传递一个int。所以它可以被修改为这个
int main()
{
int j = 1;
getFirstInteger(j)
return 0;
}
但值得一看这里的实现。您正在该方法中获得用户输入,因此不需要传递任何内容。而且您没有使用输出,所以不需要返回任何内容。
此外,您还包含了#include<iostream>
。这在小程序中不会是什么大问题,但这是一种浪费和糟糕的做法。只在需要的地方包括它(在CalculationsFunctions.cpp中)。不要认为你需要#include "stdafx.h"
。
相关文章:
- 从命令行c++发送文本文件名
- 使用新行和不使用新行读取文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 预处理器:插入结构名称中的前一个行号
- 生成随机.txt文件,10行,10列。充满随机:"*"、"#"、"@"。然后将随机字符替换为'P'
- 汇总然后平均 txt 文件中每 10 行一次
- 10'000 行后控制台中的 C++ 背景颜色错误
- 使用命令行和C++的简单计算器
- C 中的串行端口问题,Mac OS X 10.6.8
- 尝试使用for循环输出10行
- 奇怪的行为 printf( ) 每行调用 10-13 次
- 将整数列表打印为逗号分隔的数字列表,每行最多 10 个
- C++对我的命令行计算器进行故障排除
- Qt Creator 3.2.2./Mac OSX 10.9.3 Qt Creaator中未定义的符号,在命令行中确定
- 如何每10行输出一条横幅
- 我是C++的新手,需要知道第10、12和16行中发生了什么
- 简单的计算器应该需要2秒钟来修复它的10行
- 在文本文件中找到10个最大的数量行,其中包含发货ID, UPC代码,数量
- 试图从数组每行显示10个数字
- 打印出文件的最后10行