Inputting text from a text file into a 2 -D array

S

saltedcoffee

hey, I am beginer to C++ programing.
I am working on a project called the "maze Problem"
First of all I am required to read a text file in( which is the maze)
and store it into a 2 dimentional vector.
This is what I have till now:

#include <iostream>
#include "maze.h"
#include <vector>
#include <fstream>

using namespace std;

int main()
{
typedef vector< vector<char> > vectorMaze;

//get the name of the file

ifstream mazeFile;
cout<< "Enter name of file name with the maze: "<<endl;
while(!mazeFile.eof())
{
getline(cin,vectorMaze);
}

I feel there are errors with the above attempt too, but I also don't
know how to put this input into a 2-d vector.
Any help would be appreciated.
Thanks......
 
B

BobR

saltedcoffee wrote in message
hey, I am beginer to C++ programing.
I am working on a project called the "maze Problem"
First of all I am required to read a text file in( which is the maze)
and store it into a 2 dimentional vector.
This is what I have till now:

#include <iostream>
#include "maze.h"
#include <vector>
#include <fstream>
using namespace std;

int main(){
typedef vector< vector<char> > vectorMaze;

Hint: Why 'typedef' something you never use?
//get the name of the file
ifstream mazeFile;

Hint: Why declare a stream you never use?
cout<< "Enter name of file name with the maze: "<<endl;
while(!mazeFile.eof()){
getline(cin,vectorMaze);
}

Where is the end of main()?
I feel there are errors with the above attempt too, but I also don't
know how to put this input into a 2-d vector.
Any help would be appreciated.
Thanks......

You are very lost. Read this FAQ and get a book. While you are
looking/waiting for the book, download 'TiCPP'.

http://www.parashift.com/c++-faq-lite/

Get "Thinking in C++", 2nd ed. Volume 1 (&2) by Bruce Eckel
(available for free here. You can buy it in hardcopy too.):
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
 
D

Daniel T.

"saltedcoffee said:
hey, I am beginer to C++ programing.
I am working on a project called the "maze Problem"
First of all I am required to read a text file in( which is the maze)
and store it into a 2 dimentional vector.
This is what I have till now:

#include <iostream>
#include "maze.h"
#include <vector>
#include <fstream>

using namespace std;

int main()
{
typedef vector< vector<char> > vectorMaze;

//get the name of the file

ifstream mazeFile;
cout<< "Enter name of file name with the maze: "<<endl;
while(!mazeFile.eof())
{
getline(cin,vectorMaze);
}

I feel there are errors with the above attempt too, but I also don't
know how to put this input into a 2-d vector.
Any help would be appreciated.
Thanks......

You need a Matrix class, and you need to start small and work your way
up.

#include <iostream>
// put any extra includes you need here

class Matrix {
// put your code here
};

int main() {
Maxrix matrix( 1, 1 ); // create a 1 by 1 cell matrix of char
matrix.at( 0, 0 ) = 'x';
assert( matrix.at( 0, 0 ) == 'x' );
cout << "Working!\n";
}

Add code to the "put your code here" spot until you can get. The above
to compile, and when run print "Working!" on the screen. Once you get
that done, post what you have and we'll give you the next step.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top