【发布时间】:2010-11-12 03:58:55
【问题描述】:
我正在尝试编写一个使用种子生成伪随机数的程序。但是,我遇到了问题。
我收到此错误
39 C:\Dev-Cpp\srand_prg.cpp void value not ignored as it ought to be
使用此代码
#include <iostream>
#include <iomanip>
#include <sstream>
#include <limits>
#include <stdio.h>
using namespace std ;
int main(){
int rand_int;
string close ;
close == "y" ;
cout << endl << endl ;
cout << "\t ___________________________________" << endl ;
cout << "\t| |" << endl ;
cout << "\t| Pseudorandom Number Game! |" << endl ;
cout << "\t|___________________________________|" << endl ;
cout << endl << endl ;
while ( close != "y" ){
rand_int = srand(9);
cout << rand_int << endl ;
cout << " Do you wish to exit the program? [y/n] " ;
cin >> close ; }
}
【问题讨论】:
-
下面有很多很好的答案。为了将来参考,编译器消息“void value not ignored as it should be”告诉您:“您正在使用定义为不返回任何内容的函数的结果('void')”。这通常意味着您应该查看有关如何使用该功能的文档,因为您尝试的内容不正确。