Why use a new call with a C++ ‘vector’?

Your first statement is not true. The elements in vector<someType> myVector will live until the vector is destroyed. If vector<someType> is a local variable, it will be destroyed automatically when it goes out of scope. You don’t need to call delete explicitly. Calling delete explicitly is error-prone if you take into account that because of exceptions that might be thrown, your delete statement … Read more

LNK1168: cannot open debug\file.exe for writing

I have qt project but if I edit my code, Qt creator throws out this error :-1: error: LNK1168: cannot open debug\GettingStarted.exe for writing I’m not able even to delete the debug folder (i.e. as an administrator). I have to log off and then come back. What is the problem and how can I solve … Read more

Sleep function in C++

Use std::this_thread::sleep_for: There is also the complementary std::this_thread::sleep_until. Prior to C++11, C++ had no thread concept and no sleep capability, so your solution was necessarily platform dependent. Here’s a snippet that defines a sleep function for Windows or Unix: But a much simpler pre-C++11 method is to use boost::this_thread::sleep.

How to return a string from a C++ function?

You never give any value to your strings in main so they are empty, and thus obviously the function returns an empty string. Replace: with: Also, you have several problems in your replaceSubstring function: std::string::find returns a std::string::size_type (aka. size_t) not an int. Two differences: size_t is unsigned, and it’s not necessarily the same size as an int depending on your platform (eg. on 64 bits Linux or … Read more

Is there ‘byte’ data type in C++?

No there is no byte data type in C++. However you could always include the bitset header from the standard library and create a typedef for byte: NB: Given that WinDef.h defines BYTE for windows code, you may want to use something other than BYTE if your intending to target Windows. Edit: In response to … Read more