Tag Archives | c++

C++ zero padded string from int

Using an output string stream is a handy way to convert a number to a string. However, what if you want to zero pad the number. Well, that’s where iomanip comes in handy. [code language="cpp"] #include <iomanip> // for setw, setfill #include <iostream> // for cout #include <sstream> // for ostringstream #include <string> // for [...]

Continue Reading 0

C++ variable scope and the for loop

C++ allows you to re-use variables in nested scopes. A confusion arises sometimes, especially with those new to C++ rules, as to the variables at the top of a for loop. In a for loop, such as for (int i = 0; i < 2; i++) { … }, does the int i belong to [...]

Continue Reading 0