Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:08:57+00:00 2026-05-25T22:08:57+00:00

am learning vectors and made a bit of code that selects random numbers i

  • 0

am learning vectors and made a bit of code that selects random numbers i can use for buying lottery tickets here in Netherlands. But although it runs, the compiler is warning me about ‘conversion from ‘time_t’ to ‘unsigned int, possible loss of data’.

Can anyone spot what is causing this? I haven’t even defined any unsigned int in this code; int i by default is a signed int as i understand. Thanks for insight.

#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 loss of data. Line 11.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:08:58+00:00Added an answer on May 25, 2026 at 10:08 pm

    Because time_t happens to be larger in size than unsigned int on your particular platform, you get such a warning. Casting from a “larger” to a “smaller” type involves truncating and loss of data, but in your particular case it doesn’t matter so much because you are just seeding the random number generator and overflowing an unsigned int should occur for a date in the very far future.

    Casting it to unsigned int explicitly should suppress the warning:

    srand((unsigned int) time(NULL));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning the boost::lambda library and for that I wrote this sample code
I remember first learning about vectors in the STL and after some time, I
Learning a lot in my few years of programming that the best projects are
I'm currently reading Oreilly's Learning XNA 4.0 and I've noticed that the author is
I'm learning c++, and I'm a bit of a newbie. I've researched this question
In learning c++, I first use Qt library instead of the standard C++, STL
I'm learning F# from just a few days, so here's a newbie question: I've
I am trying to use std::for_each to output the contents of vectors, which may
I'm learning WPF at the moment. I have a vector graphics canvas that I'd
These questions are relatively straight forward. When using vectors, should I use the new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.