I am using stacks to create a balancing program.
I would like the user to input the name of the file to be checked for balancing but when I enter a file name like "test.cpp", which exists and has code and is in the same directory, the program crashes.
It works if I type main.cpp or anything involving main such as main_2.cpp.
Any ideas why??
This is what I'm using.
1 2 3 4 5 6 7 8
string file;
cout << "Please enter the name of file with extension to check for balancing" << endl;
cin >> file;
ifstream infile(file);
if (!infile){
cout << "Unable to open file" << endl;
return -1;
}
First : '(' , '[' and the others are one character unless '*/' and '/*'(those are two characters string)
that generates a warning .
second : about your for loop for (int i=0; i<x.size(); i++) ,you compare between a signed and unsigned interger ,which also generates a warning should be like this for (int size_t i=0; i<x.size(); i++)
finaly : I think the use of mystack.top() what makes the program crash
because in the second if ,you checking if mystack.top() == '(' ,even it is empty