[Solved] C++ vector v, vector*v, vector vec, which is the fastest (or the most efficient)? [closed]

There is a big misunderstanding here: You are comparing vectors with different semantics. It’s like asking which is faster, a glass of water or a banana. If you think about using a vector of pointers, std::vector<T*>, you need to be aware that you are using manual memory management. It might be faster in some use-cases, … Read more

[Solved] Std vector of std matrices (vector of vectors) in c++

A three dimensional vector follows the same format that a 2 dimension vector has. If A, B, C … are defined as std::vector<std::vector<double> > A (6,std::vector<double>(6)); Then their type is std::vector<std::vector<double> >. To create a vector that will hold 8 of those then you need to use std::vector<std::vector<std::vector<double>>> someName(8); If you want to have the … Read more

[Solved] Why does my is random access iterator have to be of type auto when i traverse a vector?

You don’t have to use auto if you don’t want to, but you can of course. The type returned by std::vector<int>::begin() and std::vector<int>::end() is a std:vector<int>::iterator (or std:vector<int>::const_iterator, depending on context), it is not an int. You could as well have written this instead: for(vector<int>::iterator it=vect1.begin(); it<vect1.end();it++){ cout<<*it<<endl; } or for(vector<int>::const_iterator it=vect1.begin(); it<vect1.end();it++){ cout<<*it<<endl; } … Read more

[Solved] Howto understand pointer on vector in C++

The declaration std::vector<int> * ids; says that this is a pointer to either a single object of type std::vector<int> or to (the first element of) an array of that type. The fact that operator[] is used on it in the member function shows that the second is the case. Applying operator[] to a pointer (as … Read more

[Solved] How can I create a vector in pandas dataframe from other attributes of the dataframe?

I think you need: df[‘features’] = df.values.tolist() print(df) Atr1 Atr2 features 0 1 A [1, A] 1 2 B [2, B] 2 4 C [4, C] If you have multiple columns and want to select particular columns then: df = pd.DataFrame({“Atr1″:[1,2,4],”Atr2″:[‘A’,’B’,’C’],”Atr3”:[‘x’,’y’,’z’]}) print(df) Atr1 Atr2 Atr3 0 1 A x 1 2 B y 2 4 … Read more

[Solved] C++ Storing constant varibale names within a vector [closed]

Simply use a new local variable inside your reading loop like this: while(stream >> token) { if(token == “#define”) { constantVariable addconstant; stream >> token; addconstant.constantName = token; stream >> token; addconstant.constantValue = token; constant.push_back(addconstant); } } But take care with checking the input stream. It should not be done as easy as you did … Read more

[Solved] Vector Subscript Out of Range C++ [closed]

The problem is that in the DeckOfCards class, the deck vector is never added to, so it’s empty. In the constructor, assign newDeck to deck: deck = newDeck; There is also another problem in the constructor: You declare newDeck to contain 52 entries, but then you use push_back to add new entries to the vector. … Read more

[Solved] C++: Trying to read from a file line by line, saving into a vector and then printing the vector prints nothing

You could – after skipping the line count – read in each individual character and compare it to ‘0’ or ‘1’. See the following code: int main() { vector<bool> bits; ifstream f(DATAFILE); if (f.is_open()) { int dummy; f >> dummy; char c; while (f >> c) { if (c == ‘1’) { bits.push_back(true); } else … Read more