这可能是一个非常快速的解决方法,但我无法弄清楚为什么会出现错误。
代码:
#include <iostream>
#include <queue>
#include <vector>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(int argc, char *argv[]){
srand ( time(NULL) );
double randomNumber = (double)(rand() % 100) / 100;
string numCars;
cout << "\nPlease enter the number of cars going through the intersection:" << endl;
cout << "->";
getline (cin, numCars);
for(double i=0; i<numCars; i++){
cout << randomNumber << endl;
}
}
错误是:
traffic.cpp:80: error: no match for ‘operator<’ in ‘i < numCars’