Is std::stoi actually safe to use?

Does std::stoi throw an error on the input “abcxyz”? Yes. I think your confusion may come from the fact that strtol never reports an error except on overflow. It can report that no conversion was performed, but this is never referred to as an error condition in the C standard. strtol is defined similarly by all three C standards, and I will spare … Read more

C++ #include guards

The preprocessor is a program that takes your program, makes some changes (for example include files (#include), macro expansion (#define), and basically everything that starts with #) and gives the “clean” result to the compiler. The preprocessor works like this when it sees #include: When you write: The contents of some_file almost literally get copy pasted into the file … Read more

Insert object at index of vector c++

The straight forward answer is you need an iterator. The iterator for std::vector supports random access, which means you can add or subtract an integer value to or from an iterator. The better answer is don’t use an index, use an iterator. What is your loop? You should be able to refactor the loop to … Read more

What is std::move(), and when should it be used?

Wikipedia Page on C++11 R-value references and move constructors In C++11, in addition to copy constructors, objects can have move constructors.(And in addition to copy assignment operators, they have move assignment operators.) The move constructor is used instead of the copy constructor, if the object has type “rvalue-reference” (Type &&). std::move() is a cast that produces … Read more

What is ‘\0’ in C++?

‘\0′ equals 0. It’s a relic from C, which doesn’t have any string type at all and uses char arrays instead. The null character is used to mark the end of a string; not a very wise decision in retrospect – most other string implementations use a dedicated counter variable somewhere, which makes finding the end of … Read more

printf with std::string?

It’s compiling because printf isn’t type safe, since it uses variable arguments in the C sense1. printf has no option for std::string, only a C-style string. Using something else in place of what it expects definitely won’t give you the results you want. It’s actually undefined behaviour, so anything at all could happen. The easiest way to fix this, since … Read more

Invalid use of non-static member function c++

Unlike static member functions or free functions, non-static member functions won’t implicitly convert to member function pointers. (emphasis mine) An lvalue of function type T can be implicitly converted to a prvalue pointer to that function. This does not apply to non-static member functions because lvalues that refer to non-static member functions do not exist. So you need to use & explicitly to … Read more

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