C++ error C2181: illegal else without matching if

I’m new to C++. I have been following an online course that teaches you how to make a Hangman game in C++. For the most part the code was working, every time I debugged it ran fine. I completed the entire code and double checked it, but I’m getting an error on one of the … Read more

Direct way of computing clockwise angle between 2 vectors

2D case Just like the dot product is proportional to the cosine of the angle, the determinant is proprortional to its sine. So you can compute the angle like this: The orientation of this angle matches that of the coordinate system. In a left-handed coordinate system, i.e. x pointing right and y down as is … Read more

Multiple definitions of “Main”

Multiple definitions of “main” suggests that you have another definition of main. Perhaps in another .c or .cpp file in your project. You can only have one function with the same name and signature (parameter types). Also, main is very special so you can only have one main function that can be used as the … Read more

no matching function to call for “getline”

What your teacher said is not true. cin will not “break”. It’s just that formatted extraction into an std::string is designed to read word by word. That’s intentional. It’s not broken. As for your error, your call to std::getline is broken because the delimiter argument has the wrong type. ‘\n’ is a char literal; “\n” … Read more

allocating an object of abstract class type error

This is how things works: When you declare testApp like this class testApp : public Base { … };: normal non-virtual methods are inherited as they are declared inside Base, and are immutable. normal virtual methods are inherited as they are declared inside Base, you can use them >as they already are declared, or redefine … Read more

How to find and replace string?

Replace first match Use a combination of std::string::find and std::string::replace. Find the first match: Replace the first match: A simple function for your convenience: Usage: Demo. Replace all matches Define this O(n) method using std::ostringstream as a buffer: Usage: Demo. Boost Alternatively, use boost::algorithm::replace_all: Usage:

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)