Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Inputting text from a text file into a 2 -D array

Reply
Thread Tools

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

 
 
saltedcoffee
Guest
Posts: n/a
 
      04-05-2006
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......

 
Reply With Quote
 
 
 
 
BobR
Guest
Posts: n/a
 
      04-05-2006

saltedcoffee wrote in message
<(E-Mail Removed) .com>...
>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/...ngInCPP2e.html

--
Bob R
POVrookie


 
Reply With Quote
 
 
 
 
Daniel T.
Guest
Posts: n/a
 
      04-05-2006
In article <(E-Mail Removed) .com>,
"saltedcoffee" <(E-Mail Removed)> wrote:

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


--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inputting data into a website question grocery_stocker Python 4 04-22-2009 12:02 AM
Inputting part of array into Excel Qwerty Qwerty Ruby 2 07-24-2007 01:30 PM
Inputting Text to the Runtime Parser =?Utf-8?B?amFzb253b25n?= ASP .Net 0 01-13-2006 07:57 PM
Inputting Data Into New Objects jerryalan@gmail.com C++ 3 11-13-2005 11:13 PM
Parsing bash_history and inputting into mysql (Intrusion Detection) sreekanth.hari@gmail.com Python 1 05-21-2005 02:42 AM



Advertisments