如何使用if语句测试函数
How do I test functions with an if statement
嗨,我需要一些代码方面的帮助。我需要测试一个函数,但每次尝试编译时都会遇到编译器错误。我得到的是,错误:不同指针类型"void()()"answers"const-char"之间的比较缺少强制转换。这是我的密码。
#include <iostream>
using namespace std;
void getInput();
bool gameGoing = true;
int main()
{
do{
cout << "hello world this is a test.n";
getInput();
if(getInput == "false")
{
return 0;
}
}while(gameGoing = true);
}
void getInput()
{
string userInput;
cin >> userInput;
}
应该是
#include <iostream>
using namespace std;
string getInput();
bool gameGoing = true;
int main()
{
do
{
cout << "hello world this is a test.n";
if(getInput() == "false")
return 0;
} while(gameGoing == true);
}
string getInput()
{
string userInput;
cin >> userInput;
return userInput;
}
我改变了什么:
- 为
getInput
函数添加了一个返回类型,这样它的结果就不会被忽略 - 修正了
if
比较,以实际将getInput
函数的结果与"false"
值进行比较 - 修复了while条件以比较
gameGoing
和true
值,而不是覆盖它
相关文章:
- 扩展类中的可选 vir 函数,测试它在运行时是否存在
- 有没有办法在不使用 #ifdef 的情况下不编译发布版本中的单元测试函数体?
- 使用 Google Test 对自定义断言函数进行单元测试
- 我需要将数组传递给函数以平均不同的测试分数
- 如何在使用 C 函数时测试C++代码
- 我应该在 main 函数中写什么来测试我的问题?
- 在C++单元测试上下文中,抽象基类是否应将其他抽象基类作为函数参数
- C++ gmock - 我们如何在单元测试 cpp 文件中读取/获取 cpp 文件函数的参数值
- 在类 gtest/gmock 进行单元测试时模拟成员函数C++
- 如何在 Linux 中运行 Visual Studio 2015 托管 c++ 测试函数?
- 为什么每次迭代都由 i+6 完成,为什么这个素数测试函数的条件是 i*i<=n?
- 模拟使用GoogleMock测试函数的内部呼叫
- C++类中冗余测试函数的影响
- 如何嵌入实时单元测试函数的主体作为 Doxygen 的示例用法
- 测试函数是虚拟函数还是构造函数
- 使用 Qt 进行单元测试:更改测试函数中使用的标准路径
- 如何使用if语句测试函数
- 函数拒绝在升压测试函数中工作
- Google测试函数setup()和teardown()会针对每个测试用例或整个测试套件调用
- 单元测试函数对象是否被调用