I have to write a program which balances a string with brackets.I wrote the program but it doesn't matter which string I enter because the program always says that the string is good.
Here's the code:
I used a stack and I traversed each character.If the character is an opening bracket I put it in the stack.When the character is a closing bracket, I compare it with the top of the stack.If it's good I pop the top of the stack.
> bool check(std::string s);
Presumably you're referring to this particular line.
Well the std namespace isn't yet evident to the compiler because that's in the header file, and your using statement is after that.
Ideally, you should be writing std::string and std::cin through your code.
Just saying "using namespace std;" is a lazy sop that allowed ancient C++ programs to use the standard headers without massive rewriting of the code.
Much like the special case of main assuming "return 0" as a sop to the void main programmers so all the poor dears had to do was change one word in their programs (like that was the only possible mistake to fix).
You could take a more measured approach by say
using std::cin;
using std::cout;
Do NOT be tempted to put "using namespace std;" in your header files. People will curse you.