Category : vector

C++ Help Can functions void menuSwitchListEmployees(), char menuOptionListEmployees(), void menuSwitchEmployees char menuOptionEmployees(), and void readDataFromFile be explained each in short sentences? Thank you. C++ Help Can functions void menuSwitchListEmployees(), char menuOptionListEmployees(), void menuSwitchEmployees char menuOptionEmployees(), and void readDataFromFile be explained each in a few sentences? Thank you. EmployeeList.h #pragma once #include <fstream> #include <iostream> #include ..

Read more

#include <bits/stdc++.h> using namespace std; int main() { array<vector<int>,10>arr1; arr1[0].push_back(1); arr1[0].push_back(2); arr1[0].push_back(3); arr1[1].push_back(4); arr1[1].push_back(5); arr1[2].push_back(6); arr1[7].push_back(100); for(auto i:arr1){ for(auto j :i) cout<<j<<" ";cout<<"n";} } I’m creating array of vectors and pushing some values and I can’t figure out how to make remaining places zeros. I have an idea , first making all vectors inside each ..

Read more

I hope the wording on title is correct. I have such an object in my header file std::vector<std::vector<float>> *sub; //! and in the main.cxx file it is defined as sub=0; mySetBranchAddress(tree,"sub",&sub); I want to iterate over and cout everything in another cxx file and I tried for(uint subIdx=0; subIdx < main->sub->size(); subIdx++){ for(uint subIdx2=0; subIdx2 ..

Read more

I wrote a struct to maintain a state of tic-tac-toe game. struct Board{ std::vector<std::vector<int>> board; Board() { board = std::vector<std::vector<int>> (3, std::vector<int> (3)); } std::vector<int> & operator[](int id) { return board[id]; } int & operator[](std::pair<int, int> pos) { return board[pos.first][pos.second]; } }; It works fine, and I can access the values within the struct in ..

Read more

I’m trying to avoid copying with emplace_back() and reserve(). But when I’ve tried to do it, i caught myself getting 3 copies for reason i cannot really understand. reserve() actually helps to avoid copying, but emplace_back() actually does nothing with it (works the same way as push_back() in this case). Here’s the code: struct Vertex ..

Read more