In one function of my code I found a bug. It was written std:string
:
const std::string currentDateTime() { time_t now = time(0); struct tm tstruct; char buf[80]; tstruct = *localtime(&now); //strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct); strftime(buf, sizeof(buf), "%Y%m%d%X", &tstruct); std:string str = buf; str.erase(std::remove(str.begin(), str.end(), ':'), str.end()); return str; }
The code compiles without errors. Why does it compile? What does std:string
mean then?
Differences between std::string and String Pavan. std::string is the string class from the standard C++ library. String is some other string class from some other library. It's hard to say from which library, because there are many different libraries that have their own class called String.
std::string offers a very different and much expanded interface compared to std::vector<> . While the latter is just a boring old sequence of elements, the former is actually designed to represent a string and therefore offers an assortment of string-related convenience functions.
It's called "deep copy". If only the pointer itself was copied and not the memory contents, it would be called "shallow copy". To reiterate: std::string performs deep copy in this case.
To copy c-strings in C++, strcpy() function is used.
It is interpreted as a label that can be used with goto.
int main() { //label to jump to: label_name: //some code <..> //some code goto label_name;//jump to the line with the lable }
Obviously that was a typo. Your code compiled because using namespace std;
or using std::string
was used somewhere above. Otherwise you'd get a "string was not declared in this scope" error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With