Skip to content

Commit

Permalink
correct a little mistake of ex10_05.cpp
Browse files Browse the repository at this point in the history
I found a little mistake in this answer.
  • Loading branch information
eipi10ydz committed Feb 17, 2016
1 parent 268aebc commit 4abf293
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ch10/ex10_05.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
//
// @Brief In the call to equal on rosters, what would happen if both rosters
// held C-style strings, rather than library strings?
// @Answer It's the same as `std::string`
// @Answer It's not quite the same as `std::string`
// Maybe the function 'equal' return true when you make a comparison between
// two c-style strings containers. Nonetheless, we need to keep in mind that
// when it comes to comparison of c-style strings, we need to use 'strcmp' but
// not simply relational operators, for using relational operators is just
// comparison between the address of two c-style strings but not their values.


#include <algorithm>
#include <iostream>
Expand All @@ -16,11 +22,14 @@

int main()
{
std::vector<const char*> roster1{"Mooophy", "pezy", "Queequeg"};
std::list<const char*> roster2{"Mooophy", "pezy", "Queequeg", "shbling",
"evan617"};
char c1[10] = "eipi10";
char c2[10] = "eipi10";
std::vector<char*> roster1{c1};
std::list<char*> roster2{c2};
std::cout << std::equal(roster1.cbegin(), roster1.cend(), roster2.cbegin());
return 0;
}

// clang 3.5.0
// out
// 1
// 0

0 comments on commit 4abf293

Please sign in to comment.