1. Engineering
  2. Computer Science
  3. c just need help figuring out why this file wont...

Question: c just need help figuring out why this file wont...

Question details

C++, Just need help figuring out why this file wont read in a .txt file

no errors in the code just runs out of space, can't figure out why.

any help would be appreciated

what(): error std::bad_alloc

#include <iostream>
#include "CookieList.h"
#include "CookieFile.h"
#include <cstring>

using namespace std;

int x = 0;

int main()
{
CookieFile commands;
const int MAX_CHAR = 101;

//string filename;
char filename[MAX_CHAR];


do
{
cout<<"Type in name of file: ";
//cin >> filename;
cin.getline(filename, MAX_CHAR, '\n');

//cout<<filename;
//commands.readfile(filename);
}

while(commands.readfile(filename) == false);
cout<<"Enter the number to choose the command." << endl;
cout<<"1. Print Order Summary " <<endl;
cout<<"2. Print List "<<endl;
cout<<"3. Exit "<<endl;

while (x != 3)
{
cin >> x;

switch(x)
{
case 1:
commands.printsummary();
cin.clear();
cin.ignore();
break;
case 2:
commands.printlist();
cin.clear();
cin.ignore();
break;
case 3:
return 0;
break;
default:
cout<<"Invalid Number Input"<<endl;
cout<<"Type a Valid Number" <<endl;
cin.clear();
cin.ignore();
break;
}
}
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution