C++ (something that is like a python list) -


i'm new c++ , c++ builder; working before in python. i'm working on project , need help.

i'm looking type works same list in python. have tried vector doesn't work me. need variable can store random data in. i'm using rand() numbers numbers not different repeat itself. tried boxlist , works storing items in it. have done in python can see i'm trying all.

import random pool= list() number in range(1,11):     pool.append(number) random.shuffle(pool) print(pool) 

this give me:

    [6, 2, 10, 8, 9, 3, 7, 4, 5, 1] # or other random shuffled numbers 

the other idea check if random number i'm looking in boxlist have no idea how that.

edit: im working in c++ builder , have problems getting number enter listbox.

im doing simple program me study. have 100 questions , ask me question(the number of question) , click 1 button if answer right , other if question wrong.!

the gui

this code:

    //---------------------------------------------------------------------------      #include <fmx.h>     #pragma hdrstop     #include <vector>     #include <iostream>     #include "unit3.h"     //---------------------------------------------------------------------------     #pragma package(smart_init)     #pragma resource "*.fmx"     tform3 *form3;     int right = 0;     int wrong = 0 ;     int allquestions = 0;     int currentquestion = 0;     int totheend = 0;     std::vector<int> asked;      //---------------------------------------------------------------------------     __fastcall tform3::tform3(tcomponent* owner)     : tform(owner)     {     }    //---------------------------------------------------------------------------    void __fastcall tform3::button3click(tobject *sender)    {     allquestions = edit1->text.toint();     right = 0;     wrong = 0;     label1->text = allquestions;     totheend = allquestions;      }   //---------------------------------------------------------------------------   void __fastcall tform3::button1click(tobject *sender)  {     right += 1;     totheend -= 1;     label1->text = totheend;     label3->text = right;  } //--------------------------------------------------------------------------- void __fastcall tform3::button2click(tobject *sender) {     wrong += 1;     totheend -= 1;     label1->text = totheend;     label2->text = wrong;  } //--------------------------------------------------------------------------- 

i hope guyz understand im trying here if not, plz tell me.

it's not clear me why std::vector won't work you, because has similar properties python's list type.

#include <iostream> #include <vector> #include <algorithm>  int main() {     std::vector<int> pool;      (int i=1; i<11; ++i)         pool.push_back(i);      std::random_shuffle(pool.begin(), pool.end());      (std::vector<int>::const_iterator = pool.begin(); != pool.end(); ++i)         std::cout << *i << " ";     std::cout << "\n";      // or, print way:     (int i=0; i<pool.size(); ++i)         std::cout << pool[i] << " ";     std::cout << "\n"; } 

this code outputs:

[7:47am][wlynch@watermelon /tmp] ./ex 6 10 7 4 8 9 5 2 3 1  6 10 7 4 8 9 5 2 3 1  

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -