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 8169977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:01:17+00:00 2026-06-06T21:01:17+00:00

Thank you very much for the answer. The reason that makes me think about

  • 0

Thank you very much for the answer.

The reason that makes me think about checking the content of the vector is that even after I overwrite it, the same (strange) values remain. My purpose is to generate iteratively some random variables and put them in the two dimensional vector. I give you my code, maybe I am doing something wrong:

while (nbre_TTI_tempo != 0 ) 

{
   srand(time(NULL)) ;  

 while (nbre_UE_tempo != 0 )
{ 
  vect.clear() ; 

  nbre_PRB_tempo = nbre_PRB ; 

while (nbre_PRB_tempo != 0) 
 {  

 value = rand() % 15 + 1 ;  // generating random variables between 1 and 15

vect.push_back(value) ; 

  nbre_PRB_tempo -- ; 


   }



 All_CQI.push_back(vect) ; 

 nbre_UE_tempo -- ; 

}

// Do business 

All_CQI.clear();

} .// end while

At the first round, everything goes well, but at the second one, this is what I find in the vector after the use of the method “clear”:

158429184
14
15
158429264
10
9
158429440
5
1

And when I try to overwrite it, I find:
158429184
14
15
158429264
10
9
158429440
5
1

Which are the same values as before using the method “push_back”.
Do you think I’m doing something wrong in my code?
Thank you very much in advance for your help.

  • 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-06-06T21:01:19+00:00Added an answer on June 6, 2026 at 9:01 pm

    For your purpose, if empty() returns true, you should trust that it is empty and SHOULD NOT check for individual elements. It is illegal to access the contents of an empty vector thus and can cause memory access errors.

    The reason you find values is because the actual memory locations are not overwritten immediately- they are only marked as invalid. Until some other object is allocated the same memory, the data may remain as it is – but there is no way to be sure – the implementation is left to the compiler.

    Looks like you are using the array operator[] to access the elements. To be safer, use the iterator or the .at() method to access the elements. Both these methods perform bounds checking and will not let you go beyond the last valid element

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Answer found! Thank you very much people, a lot of answers worked, I
Thank you very much in advance for reading. I'm programming a web application in
My apologies as I'm very much a Java noob. Anyways, I think I've dumbed
I have a problem which makes me crazy. I think it is very easy
i have very serious problem if any tech expert can help...thank you in advance..
First and foremost, thank you all for reading this and helping, I'm very grateful.
I got over a problem, I think a very specific one. I've got 2
Today I found LiquiBase project and I think it is very interesting. I would
Today I got this question for which I think I answered very bad. I
Disclaimer: I am using ExtJS 3, but I don't think it's very relevant to

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.