所以,我有一個std::list<std::string>
,我問,如果有一個函數或把戲隨機列表。隨機化一個std ::列表<std::string>
例子:
first elem of the list : "Hello"
second elem of the list : "Stack"
third elem of the list : "Over"
fourth elem of the list : "Flow"
fifth elem of the list : "!!"
我要的是一個函數或手段來得到這樣一個隨機的列表,例如:
first elem of the list : "Flow"
second elem of the list : "!!"
third elem of the list : "Hello"
fourth elem of the list : "Stack"
fifth elem of the list : "Over"
我想你明白我的意思:)
http://en.cppreference.com/w/cpp/algorithm/random_shuffle –
@ πάνταῥεῖ:對'std :: list'不起作用。但是,再次,爲什麼OP使用列表而不是矢量? –
具體來說,'random()'或'random_shuffle()'不適用於不提供隨機訪問迭代器的容器。如前所述,'std :: list'是一個非常不尋常的**容器選擇。幾乎總是。 –