By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

How to Read and Display 2D text file?

P: 1
#include<iostream>
#include<fstream>
#include<conio.h>
#include<string>

using namespace std;

void openfile()
{

}

void main()
{
int maze[20][100] = { 0 };
string row;
ifstream fname;
fname.open("mazefile.txt");
if (fname.is_open())
{
for (int j = 0; j < 19; j++)
for (int i = 0; i < 99; i++)
{
fname >> maze[j][i];

if (maze[j][i] == 1)
_putch('219');
if (maze[j][i] == 0)
_putch(' ');

}

}
fname.close();
system("pause");
}


that is what I have so far although every time I debug it, the first value is always a bunch of random numbers. Then just garbage after that. Any help would be greatly appreciated.
Mar 12 '19 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.