|
-
March 24th, 2012, 07:25 PM
#1
Having trouble with a readin. Can't read in a matrix into vector of vector of int.
I had posted this on another place, but since the issue right now is reading in, it can go here. Also, I noticed the other place was getting very few replies for anyone that posted there (i.e. low traffic) Not just for me, but few people seemed to be going there in general and the last post before mine was March 9th and it still hadn't been answered. And the last post before that was either also March 9th or was in February.
http://forums.codeguru.com/showthrea...74#post2061574
Code:
#include <iostream>
#include <istream>
#include <fstream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
int size;
vector<vector<int> > nums;
fstream fin;
fin.open(argv[1]);
int temp;
// reader >> temp;
// nums.push_back(temp);
// fin >> temp;
//nums.push_back(temp);
while (fin >> temp)
{
nums.push_back(vector<int>());
while (!fin.peek() == '\n')
{
nums[size].push_back(temp);
}
size++;
}
fin.close();
for (int i =0; i < nums.size(); i++)
{
for (int j =0; j < nums[i].size(); j++)
{
cout << nums[i][j] << " ";
}
cout << "\n";
}
cout << "\n" << nums.size();
}
Why is it reading in nothing for the arrays, and also making the size of the total thing the total number of numbers? It should have a size of 2, not 5.
I've spent the past few hours on this and am getting nowhere. And I still need to work on the threading part.
Please help.
Last edited by jedipenguin; March 24th, 2012 at 07:28 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|