Storing integers values from file into a vectors of vector

Storing integers values from file into a vectors of vector

By : J Edwin Monsalve
Date : October 22 2020, 06:10 AM
I hope this helps . Each iteration of your loop needs to do two things:
create a new inner vector in links add the three elements to the newly created inner vector
code :
while (...)
#if 0
    // create new inner vector (C++17 version)
    auto& inner = links.emplace_back();
    // create new inner vector (C++11 version)
    auto& inner = links.back();

    // insert elements

Share : facebook icon twitter icon
OpenCV storing vectors of vectors of points vector<vector<Point> >

OpenCV storing vectors of vectors of points vector<vector<Point> >

By : Hamza Deutz
Date : March 29 2020, 07:55 AM
I wish did fix the issue. For the moment, I solved this by just not using OpenCV's FileStorage. Here is what I did for storing a vector of vector of Point since there are good routines for printing the vectors.
code :
bool writeVectorVectorPoint(string fname, vector<vector<Point> > vvP)
  ofstream fsOut;
  vector<vector<Point> >::iterator p;

    cout << "Failed to open " << fname << endl;
  for(p = vvP.begin(); p != vvP.end(); p++)
    fsOut << (*p) << endl;
bool readVectorVectorPoint(string fname, vector<vector<Point> >& vvP)
  ifstream fsIn;
    cout << "Failed to open: " << fname << endl;
  Point pt;
  vector<Point> vPt;
  vector<Point>::iterator p;
  string line;
  while(getline(fsIn, line))
    cout << line << endl;
    string ptStr;
    stringstream s(line.substr(1,line.size()-1));
    while(getline(s, ptStr, ';'))
      stringstream s1(ptStr);
      string lastStr;
      getline(s1, lastStr, ',');
      pt.x = atoi(lastStr.c_str());
      getline(s1, lastStr, ',');
      pt.y = atoi(lastStr.c_str());

Reading a text file (with integers) row by row and storing each row as a vector (C++)

Reading a text file (with integers) row by row and storing each row as a vector (C++)

By : R.thakur
Date : March 29 2020, 07:55 AM
wish helps you I'm working on graph theory problems and using the adjacency list implementation. I have long text files which represent the adjacency list of graphs with N>100 vertices. , This small example, should show one way of doing this:
code :
#include <vector>
#include <sstream>
#include <iostream>
#include <string>
#include <iterator>
int main()
    // use a typedef to simplify things a bit 
    typedef std::vector<int> Int1D;
    typedef std::vector<Int1D> Int2D;

    // declare the adjacency list
    Int2D adjList;

    std::string line;
    std::ifstream infile;
    //..assume that infile has been opened successfully
    while (std::getline(infile, line))
       // use a string stream to help parse the ints
       std::istringstream strm(line);
       int n;

       // add an empty row

       // now fill in the last row we added by reading in the ints
       while (strm >> n)

    // output results
    for (size_t i = 0; i < adjList.size(); ++i)
       std::copy(adjList[i].begin(), adjList[i].end(), std::ostream_iterator<int>(std::cout, " "));
       std::cout << '\n';
Sum of vector of vectors of vectors ... of integers

Sum of vector of vectors of vectors ... of integers

By : Tejaswin Renugunta
Date : March 29 2020, 07:55 AM
it helps some times Reading your error message. It looks like your functions are in a separate compilation unit from main.cpp. If your functions are in a .h file, #include the header file in main.cpp.
I would suggest using the template specialization declaration:
code :
int sumAllElements(std::vector<int> v)
Storing and reading integers into a vector array from .txt file

Storing and reading integers into a vector array from .txt file

By : user1616444
Date : March 29 2020, 07:55 AM
it should still fix some issue Never use both stdio and iostream. For files it'd be better if you used fstream, like this:
code :
#include <fstream>

ifstream fin("sample.txt");

int number;

while(fin >> number)
Storing Matrix information in STL vector. Which is better vector or vector of vectors?

Storing Matrix information in STL vector. Which is better vector or vector of vectors?

By : Evgeny Lisin
Date : March 29 2020, 07:55 AM
I wish this help you Have you considered using an off-the-shelf matrix representation such as boost's instead of reinventing the wheel?
If you have a lot of empty rows for example, using the nested representation could save a lot of space. Unless you have specific information in actual use cases showing one way isn't meeting your requirements, code the way that's easiest to maintain and implement properly.
Related Posts Related Posts :
  • Can I trust floats or doubles representing integers to retain precision?
  • Qt execute multiple get with QNetworkAccessManager
  • Big and Little endian question
  • Visual Studio 2008 compiles anything in C++ file?
  • C++ pointer to functions, Beginner Question
  • Fastest algorithm for primality test
  • Passing array of pointers to another class
  • Handling macro redefinition without modifying .h files ... C / C++ language
  • Implement SSL with SSPI: How to start?
  • Creating a simple VS2008 visualizer inside autoexp.dat (problem with casting)
  • C++ - Unicode Newline
  • Program crashing with 'std::out_of_range' error
  • Use signed or unsigned char in constructing CString?
  • Parallel execution policies in C++ 17
  • C++ Class Templates (Queue of a class)
  • Convert image into useable byte array in C?
  • pointer to preallocated memory as an input parameter and have the function fill it
  • Animated Image in Win32
  • error on compiling statically linked library created in Qt
  • How to easily pass a very long string to a worker process under Windows?
  • Can a class add friend classes at runtime in C++?
  • C++ priority queue in ascending order by specific method for objects
  • Initialize and declare dynamically multiple variables of random entities in a loop in C++
  • Serializing, integer without libaries , getting weird results
  • Function pointers with default parameters in C++
  • Compilation errors with RapidXML
  • Bad_alloc exception when using new for a struct c++
  • count specific things within a code in c++
  • How to extract 48*48 icon image from resource of an executable file?
  • C++ Convert string (or char*) to wstring (or wchar_t*)
  • C++ include .h includes .cpp with same name as well?
  • Any way in C++ to forward declare a function prototype?
  • boost graph adjacency_list, retrieving a node's parents
  • Copy method optimization in compilers
  • what the problem in this program? it doesn't use the second number, and doesn't print the last line?
  • Need to format character precedence in Strings
  • Cross-Platform Camera API
  • sizeof continues to return 4 instead of actual size
  • String search algorithm used by string::find() c++
  • Two-phase lookup: can I avoid "code bloat"?
  • Strongest cipher available to use with C/C++?
  • Why does my program occasionally segfault when out of memory rather than throwing std::bad_alloc?
  • Firefox XULRunner or TriXul?
  • Does GetSystemInfo (on Windows) always return the number of logical processors?
  • Where is the difference between these code? Shouldn't output be the same?
  • What does it mean mean by "Expected a statement" in C++
  • keybd_event is not working right =(
  • What native C++ profiling tool do you suggest?
  • how to copy char * into a string and vice-versa
  • C++ write to front of file
  • Delphi conversion of C++ header for DVP7010B video card DLL?
  • I keep Getting Control reaches end of non-void function. What am I doing wrong?
  • How to have struct members accessible in different ways
  • Am I abusing Policies?
  • Modern equivalent of BoundsChecker for Visual Studio 2008
  • exposing subcontrols from the custom widget plugin in QT
  • How to execute a function called many times, only once !
  • How to use Ptrace on Linux to print Call Stack of Other Processes of C++
  • BOOST.IOstreams: trouble to write to bzip2
  • C++ MIDI file reading library
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk