473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

Apr 5 '06 #1
2 2370

saltedcoffee wrote in message
<11**********************@i39g2000cwa.googlegroups .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
Apr 5 '06 #2
In article <11**********************@i39g2000cwa.googlegroups .com>,
"saltedcoffee" <as***********@hotmail.com> 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.
Apr 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Kruton | last post by:
What is the easiest way to take a string from a console while including whitespaces? This program's user will input a line of text that will consist of multiple tokens, but the number tokens and...
1
by: C G | last post by:
Dear All, I have a text file with data like: 1 2 3 4 5 6 7 8 9 i.e. so I have three columns of numbers. I wish to put this data into a table. However, I do not want it to take up three...
0
by: jasonwong | last post by:
Hi, I was wondering if anyone knows of a way to utilize the Runtime Parser to parse a text box filled with user input code. The user will be inputting HTML and data markup into a textbox that...
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
1
by: Ramper | last post by:
Have a .txt document as: String int int int int int int int
2
by: UofFprogrammer | last post by:
Hello, Several Weeks ago I asked a question about testing for the end of an input file. I have been using this method pretty well for inputting information from an external file. I am using C++. ...
5
by: tim123 | last post by:
Hey. I'm having some issues reading in data from a tab delimited text file. I only want to input numbers, and ideally I'd like it to be able to cope with a line or 2 of text at the top in case...
1
by: shadowofanubis66 | last post by:
Basically, the project I'm working on this week is to make a school lunch menu with a GUI, when the person types in a day, the menu for that day shows up. We have two files, ones a day off text file...
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.