Why use string::iterator rather than index?

The index can only be used for containers that support random access – direct access to a given position. The iterator offers a unified way to access any collection/data structure. The flexibility when refactoring your code is immense.

How do I tokenize a string in C++?

C++ standard library algorithms are pretty universally based around iterators rather than concrete containers. Unfortunately this makes it hard to provide a Java-like split function in the C++ standard library, even though nobody argues that this would be convenient. But what would its return type be? std::vector<std::basic_string<…>>? Maybe, but then we’re forced to perform (potentially redundant and costly) … Read more

Is there a tab equivalent of std::endl within the standard library?

No. std::endl isn’t a newline constant. It’s a manipulator which, in addition to inserting a newline, also flushes the stream. If you just want to add a newline, you’re supposed to just insert a ‘\n’. And if you just want to add a tab, you just insert a ‘\t’. There’s no std::tab or anything because inserting a tab plus flushing the stream is not exactly a common operation.

How to convert a std::string to const char* or char*

If you just want to pass a std::string to a function that needs const char* you can use If you want to get a writable copy, like char *, you can do that with this: Edit: Notice that the above is not exception safe. If anything between the new call and the delete call throws, you will leak memory, as nothing will call delete for you … Read more

srand(time(0)) and random number generation

srand() gives the random function a new seed, a starting point (usually random numbers are calculated by taking the previous number (or the seed) and then do many operations on that number to generate the next). time(0) gives the time in seconds since the Unix epoch, which is a pretty good “unpredictable” seed (you’re guaranteed your seed … Read more

Cannot open include file: ‘stdio.h’ – Visual Studio Community 2017 – C++ Error

There are three ways to solve this issue. Ignore Precompiled Headers #1Steps: Project > Properties > Configuration Properties > C/C++ > Command Line > in the Additional Options box add /Y-. (Screenshot of Property Pages) > Ok > Remove #include “stdafx.h” Ignore Precompiled Headers #2Steps: File > New > Project > … > In the Application Wizard Window … Read more

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