am studying vectors and made some code that selects random numbers that I can use to buy lottery tickets here in the Netherlands. But, although it works, the compiler warns me of a "conversion from" time_t "to" unsigned int, possible data loss. "
Can anyone determine what causes this? I have not even defined any unsigned int in this code; int i by default is a signed int, as i understand it. Thank you for understanding.
#include <iostream> #include <vector> #include <string> #include <ctime> using namespace std; void print_numbers(); string print_color(); int main() { srand(time(NULL)); print_numbers(); string color = print_color(); cout << color << endl; system("PAUSE"); return 0; } //Fill vector with 6 random integers. // void print_numbers() { vector<int> lucky_num; for (int i = 0; i < 6; i++) { lucky_num.push_back(1 + rand() % 45); cout << lucky_num.at(i) << endl; } } //Select random color from array. // string print_color() { string colors[6] = {"red", "orange", "yellow", "blue", "green", "purple"}; int i = rand()%6; return colors[i]; }
Exact compiler message: warning C4244: "argument": conversion from "time_t" to "unsigned int", possible data loss. Line 11.
source share