Navigation



17.6 — std::string appending

Appending

Appending strings to the end of an existing string is easy using either operator+=, append(), or push_back() function.

string& string::operator+= (const string& str) string& string::append (const string& str)

Both functions append the characters of str to the string. Both function return *this so they can be “chained”. Both functions throw a length_error . . . → Read More: 17.6 — std::string appending

17.5 — std::string assignment and swapping

String assignment

The easiest way to assign a value to a string is to the use the overloaded operator= function. There is also an assign() member function that duplicates some of this functionality.

string& string::operator= (const string& str) string& string::assign (const string& str) string& string::operator= (const char* str) string& string::assign (const char* str) string& . . . → Read More: 17.5 — std::string assignment and swapping

13.2 — Input with istream

The iostream library is fairly complex — so we will not be able to cover it in it’s entirety in these tutorials. However, we will show you the most commonly used functionality. In this section, we will look at various aspects of the input class (istream).

Note: All of the I/O functionality in this . . . → Read More: 13.2 — Input with istream

Eight C++ programming mistakes the compiler won’t catch

C++ is a complex language, full of subtle traps for the unwary. There is an almost infinite number of ways to screw things up. Fortunately, modern compilers are pretty good at detecting a large number of these cases and notifying the programmer via compile errors or warnings. Ultimately, any error that is compiler-detectable . . . → Read More: Eight C++ programming mistakes the compiler won’t catch

5.7 — For statements

By far, the most utilized looping statement in C++ is the for statement. The for statement is ideal when we know exactly how many times we need to iterate, because it lets us easily declare, initialize, and change the value of loop variables after each iteration.

The for statement looks pretty simple:

for (init-statement; . . . → Read More: 5.7 — For statements