我正在嘗試編寫一個程序,該程序使用種子生成僞隨機數。但是,我遇到了問題。srand(),C++的問題
我得到這個錯誤
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')」。這通常意味着你應該檢查關於函數應該如何使用的文檔,因爲你正在嘗試的是不正確的。 – 2010-11-12 04:12:25