C++ Initializing a Global Array

If you actually want an array and not a vector, and you want that array dynamically sized at runtime, you would need to create it on the heap (storing it in a pointer), and free it when you’re done. Coming from Java you need to understand that there’s no garbage collection in C++ – anything … Read more

How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?

Use rfind overload that takes the search position pos parameter, and pass zero for it: Who needs anything else? Pure STL! Many have misread this to mean “search backwards through the whole string looking for the prefix”. That would give the wrong result (e.g. string(“tititito”).rfind(“titi”) returns 2 so when compared against == 0 would return false) and it would be inefficient (looking through … Read more

Using multiple .cpp files in c++ program?

You must use a tool called a “header”. In a header you declare the function that you want to use. Then you include it in both files. A header is a separate file included using the #include directive. Then you may call the other function. other.h main.cpp other.cpp

Random not declared in scope

random is not a standard C++ function; it’s a POSIX function, so it’s not available on Windows. Use rand instead, or better, the new C++11 randomness library.

Function definition not found for a function declared inside unnamed namespace – how to resolve? (Visual Studio 2015)

The green squiggles don’t tell you that there’s an error, they tell you that there’s an opportunity for the new refactoring tools to do something. (Red squiggles indicate an error.) In this case, they’re informing you that there is no definition matching the declaration of test2, so the IDE is offering to generate one. This happens … Read more

to_string not declared in scope

There could be different reasons why it doesn’t work for you: perhaps you need to qualify the name with std::, or perhaps you do not have C++11 support. This works, provided you have C++11 support: To enable C++11 support with g++ or clang, you need to pass the option -std=c++0x. You can also use -std=c++11 on the newer versions … Read more

Reading string by char till end of line C/C++

You want to use single quotes: Double quotes (“) are for strings, which are sequences of characters. Single quotes (‘) are for individual characters. However, the end-of-line is represented by the newline character, which is ‘\n’. Note that in both cases, the backslash is not part of the character, but just a way you represent … Read more

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