C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# 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)
#else
// create new inner vector (C++11 version)
#endif

// insert elements
inner.push_back(a);
inner.push_back(b);
inner.push_back(c);
}
``````

Share :

## 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;

fsOut.open(fname.c_str());
if(fsOut.fail())
{
cout << "Failed to open " << fname << endl;
return(false);
}
for(p = vvP.begin(); p != vvP.end(); p++)
{
fsOut << (*p) << endl;
}
fsOut.close();
return(true);
}
``````
``````bool readVectorVectorPoint(string fname, vector<vector<Point> >& vvP)
{
ifstream fsIn;
fsIn.open(fname.c_str());
if(fsIn.fail())
{
cout << "Failed to open: " << fname << endl;
return(false);
}
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));
vPt.clear();
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());
vPt.push_back(pt);
}
vvP.push_back(vPt);
}

fsIn.close();
return(true);
}
``````

## 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;

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;

// 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::cout << '\n';
}
}
``````

## 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 :
``````template<>
int sumAllElements(std::vector<int> v)
{
...
}
``````

## 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)
{
numArray.push_back(number);
}
``````

## 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.