赛马程序,忽略函数调用
Horse race program, function call ignored
打印出代码时,它会运行,但似乎没有运行coinflip()
函数。目前只尝试打印出第一根马绳,随机向前移动。
#include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;
string h0 = "0................";
string h1 = "1................";
string h2 = "2................";
string h3 = "3................";
string h4 = "4................";
int position0 = 0;
string coinflip0(string h0);
int main(){
cout << "Press Enter to begin! " <<endl;
cin.ignore();
std::cout << h0 << endl; //print string
cout << h1 << endl;
cout << h2 << endl;
cout << h3 << endl;
cout << h4 << endl;
// srand(time(NULL));//time goes back to zero for each loop
while(h0.at(16) != 0) {
cout << "n Press Enter to continue " << endl;
cin.ignore();
string coinflip0(h0); // call function
cout << h0 << endl; //print new string
} //end while
} // end main
string coinflip0(string h0) {
// find random number(0 or 1)
int num = rand() % 2;
cout << num << endl;
position0 = position0 + num;
if(num==1){
std::swap(h0[position0], h0[position0+1]);
} // end if
return h0;
}//end coin flip
输出:
Press Enter to begin!
0................
1................
2................
3................
4................
Press Enter to continue
0................
Press Enter to continue
0................
Press Enter to continue
0................
Press Enter to continue
string coinflip0(h0); // call function
这实际上不是函数调用。它是一个变量声明,类似于:
string coinflip0 = h0;
要调用该函数,请省略string
.一个简单的coinflip0(h0)
就可以了。我认为您想将结果分配回h0
,所以也这样做:
h0 = coinflip0(h0);
相关文章:
- 使用动态链接加载程序 <dlfcn.h> 而不是直接函数调用的目的是什么?
- 赛马程序,忽略函数调用
- C++实用程序,用于将长开关语句转换为封装开关案例阶梯的简洁函数调用
- 从函数调用C++程序?
- 获取调用函数调用的C++程序中的所有行号
- 当在函数调用中递增值时,程序正常工作,但是如果我们在单独的行中增加值而不是呼叫函数,则会出现错误.为什么
- 如何从LLVM的中间表示中获取在程序的每个函数中执行的函数调用列表
- 如何从另一个函数中调用的函数结束程序 (C++)
- 使用指针的矢量矩阵在对象上调用析构函数时程序崩溃
- 关于函数调用,我的程序没有读取我的其他函数。为什么?
- 当指定初始化程序的顺序和字段声明不一致时,clang可以删除函数调用
- 尝试复制数组时从 DLL 调用函数时程序崩溃
- 调试:跟踪(和diffing)同一程序的两个版本的函数调用树
- C++ 尝试通过内存中的地址调用函数时程序崩溃(如何修复?
- 标准 C++ 程序执行期间的函数调用
- mfc应用程序结束后,CMainFrame的析构函数调用发生访问冲突
- 调用构造函数后程序崩溃
- 等待从获取锁的函数调用的帮助程序函数中的条件变量
- 使用可变包类型扩展的C++函数调用程序包装
- 主函数调用程序中的错误标记