.....xx........
....x..xx......
....x....xxxx..
...x........xxx
..x...*........
...x........xx.
...x..xxx...x.x
...x..x..x.x...
...xxxx...x....
...............
Into a two dimensional vector of chars. So what I was thinking was that I should use the getline function to input each line into a string. Then, I would input the characters of the string into the vector. Now, my problem is how I would make more rows, as this would only input the first row. I don't know if I can use the pushback function or the resize function, an explanation on how to edit each dimension of the vector would be greatly appreciated. Anyways, this was my best attempt at the program, but when I compile it, it doesn't display anything and returns some obscure number (also, I am using code::blocks if that is any help)...
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
ifstream infile("C:/Documents and Settings/Stefan Schembor/My Documents/Softmore Programming/picture.txt");
if (!infile)
{
cout<<"File could not be opened."<<endl;
exit(1);
}
vector<vector<char> >picture(1); //one by one vector
string line;
int rows=0;
while(getline(infile, line))
{
picture.resize(line.size()); //resize vector horizontally to fit the string
for(int x=0; x<picture.size(); x++)
picture[rows][x]=line[x]; //input string into array
for(int x=0; x<picture.size(); x++)
picture[x].resize(picture[x].size()+1); //resize vector vertically by one
rows++;
}
//display picture
for(int y=0; y<picture[y].size(); y++)
{
for(int x=0; x<picture.size(); x++)
cout<<picture[y][x];
cout<<endl;
}
return 0;
}
If I posted this in the wrong section, or did this wrong, please tell me so that I can do it right next time. Thanks for your help!

New Topic/Question
Reply




MultiQuote




|