Created
June 29, 2013 18:21
-
-
Save DForshner/5892128 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const int values[] = {0,1,2,3,4,5,6,7,8,9}; | |
vector<int> v (values, values + sizeof(values) / sizeof(values[0]) ); | |
// Using C++11 ranged-based for loop | |
std::stringstream ss; | |
for (int n : v) | |
ss << n; | |
Assert::IsTrue(ss.str() == "0123456789"); | |
ss.str(""); ss.clear(); // clear string stream | |
// Using iterators | |
for (auto n = v.begin(); n != v.end(); ++n) | |
{ | |
ss << (int)*n; | |
} | |
Assert::IsTrue(ss.str() == "0123456789"); | |
ss.str(""); ss.clear(); // clear string stream | |
// Using std::for_each with lambda | |
std::for_each(v.begin(), v.end(), [&ss] (int val) | |
{ | |
ss << val; | |
}); | |
Assert::IsTrue(ss.str() == "0123456789"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment