c++operators

no match for ‘operator<’


This is probably a very quick fix, but I'm having trouble figuring out why I'm getting an error.

Code:

#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;
    }

}

The error is:

 traffic.cpp:80: error: no match for ‘operator<’ in ‘i < numCars’

Solution

  • numCars is a string. It should have integer type (char, short, int, long)