stl

Dynamically change text qlabel

血红的双手。 提交于 2021-02-17 03:16:43
问题 Sorry for my english. I need to change the text qlabel dynamically. class Game: { ... std::shared_ptr<QWidget> m_hint; QLabel *m_label; QHBoxLayout *m_layout; } void Game::setTextToHint(std::string str) { m_label = new QLabel(); m_layout = new QHBoxLayout(); m_label->setText(QString::fromUtf8(str.c_str())); m_layout->addWidget(m_label); m_hint->setLayout(m_layout); } And i use this function eg twice: setTextToHint("One"); setTextToHint("First"); But ultimately label = "One" Ok i understood. I

Dynamically change text qlabel

心不动则不痛 提交于 2021-02-17 03:15:02
问题 Sorry for my english. I need to change the text qlabel dynamically. class Game: { ... std::shared_ptr<QWidget> m_hint; QLabel *m_label; QHBoxLayout *m_layout; } void Game::setTextToHint(std::string str) { m_label = new QLabel(); m_layout = new QHBoxLayout(); m_label->setText(QString::fromUtf8(str.c_str())); m_layout->addWidget(m_label); m_hint->setLayout(m_layout); } And i use this function eg twice: setTextToHint("One"); setTextToHint("First"); But ultimately label = "One" Ok i understood. I

C++ Set: No match for - operator

拈花ヽ惹草 提交于 2021-02-16 20:06:56
问题 I have a set, namely of type multiset , I'm trying to use the upper_bound function to find the index of the element returned by the iterator. Usually with vectors, it works if I get the iterator and subtract vector.begin() from it to get the answer. However, when I try this with a set it gives an STL error, saying "no match for operator -' in ...(omitting STL details) Is there a fundamental reason for this ( sets being implemented as RB-trees and all). If so, can anyone suggest an alternate

C++ Set: No match for - operator

∥☆過路亽.° 提交于 2021-02-16 20:06:35
问题 I have a set, namely of type multiset , I'm trying to use the upper_bound function to find the index of the element returned by the iterator. Usually with vectors, it works if I get the iterator and subtract vector.begin() from it to get the answer. However, when I try this with a set it gives an STL error, saying "no match for operator -' in ...(omitting STL details) Is there a fundamental reason for this ( sets being implemented as RB-trees and all). If so, can anyone suggest an alternate

what is sizeof() operator doing in C++

Deadly 提交于 2021-02-16 09:20:50
问题 The sizeof() operator in C gives the size of its operand at compile time. It does not evaluate its operand. For example, int ar1[10]; sizeof(ar1) // output 40=10*4 sizeof(ar1[-1]) // output 4 int ar2[ sizeof(ar1) ]; // generate an array of 40 ints. When it came to C++ template class, I find some strange result. template<typename T> struct S{ T a; }; sizeof( S<int> ) // output 4 sizeof( S<bool> ) // output 1 sizeof( vector<int> ) // output 24 sizeof( vector<char> ) // output 24 sizeof( vector

How does subtracting X.begin() return the index of an iterator?

有些话、适合烂在心里 提交于 2021-02-13 17:27:49
问题 Having trouble understanding the below code: int data[5] = { 1, 5, 2, 4, 3 }; vector<int> X(data, data+5); int v1 = *max_element(X.begin(), X.end()); // Returns value of max element in vector int i1 = min_element(X.begin(), X.end()) – X.begin(); // Returns index of min element in vector Not really sure how subtracting the iterator returned by X.begin returns the index of the max/min element? 回答1: std::vector<T>::iterator satisfies the RandomAccessIterator concept, which means that it has an

How does subtracting X.begin() return the index of an iterator?

微笑、不失礼 提交于 2021-02-13 17:25:50
问题 Having trouble understanding the below code: int data[5] = { 1, 5, 2, 4, 3 }; vector<int> X(data, data+5); int v1 = *max_element(X.begin(), X.end()); // Returns value of max element in vector int i1 = min_element(X.begin(), X.end()) – X.begin(); // Returns index of min element in vector Not really sure how subtracting the iterator returned by X.begin returns the index of the max/min element? 回答1: std::vector<T>::iterator satisfies the RandomAccessIterator concept, which means that it has an

initialing stl collection elements (not pointers) when no default constructor?

随声附和 提交于 2021-02-11 16:52:28
问题 I have such private field: private: std::vector<OneItemIndex> oneItemIndexes; My class declared this way, there are no default constructor: public OneItemIndex(int instrumentId) I want my field to contain 10 elements like this: oneItemIndexes 0 OneItemIndex(0) 1 OneItemIndex(1) ... 10 OneItemIndex(10) How can I do this? What should I write in constructor? Is it possible? Or I have to use OneItemIndex* instead of OneItemIndex and call new OneItemIndex(instrumentId myself this way?

initialing stl collection elements (not pointers) when no default constructor?

时光毁灭记忆、已成空白 提交于 2021-02-11 16:47:32
问题 I have such private field: private: std::vector<OneItemIndex> oneItemIndexes; My class declared this way, there are no default constructor: public OneItemIndex(int instrumentId) I want my field to contain 10 elements like this: oneItemIndexes 0 OneItemIndex(0) 1 OneItemIndex(1) ... 10 OneItemIndex(10) How can I do this? What should I write in constructor? Is it possible? Or I have to use OneItemIndex* instead of OneItemIndex and call new OneItemIndex(instrumentId myself this way?

Is there any data structure in C++ STL for performing insertion, searching and retrieval of kth element in log(n)?

好久不见. 提交于 2021-02-11 04:29:50
问题 I need a data structure in c++ STL for performing insertion, searching and retrieval of kth element in log(n) (Note: k is a variable and not a constant) I have a class like class myClass{ int id; //other variables }; and my comparator is just based on this id and no two elements will have the same id. Is there a way to do this using STL or I've to write log(n) functions manually to maintain the array in sorted order at any point of time? 回答1: Afaik, there is no such datastructure. Of course,