Skip to content

Commit

Permalink
refuctor ex9_41 and move ex9_42 to README
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Dec 4, 2014
1 parent d9d23f1 commit 9b355f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 43 deletions.
7 changes: 7 additions & 0 deletions ch09/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,10 @@ svec.resize(svec.size()+svec.size()/2); // sets capacity to at least 3/2's size.
|512 |1024 |
|1000 |1024 |
|1048 |1572 |

## [Exercise 9.41](ex9_41.cpp)

## Exercise 9.42:
>Given that you want to read a character at a time into a string, and you know that you need to read at least 100 characters, how might you improve the performance of your program?
Use member `reserve(120)` to allocate enough space for this string. (@Mooophy)
24 changes: 24 additions & 0 deletions ch09/ex9_41.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ex9_41.cpp
// Exercise 9.41
//
// Created by pezy on 12/4/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// @Brief Write a program that initializes a string from a vector<char>.

#include <iostream>
#include <vector>
#include <string>

using std::vector; using std::cout; using std::endl; using std::string;

int main()
{
vector<char> vec{'p', 'e', 'z', 'y'};
string str(vec.begin(), vec.end());

cout << str << endl;

return 0;
}
43 changes: 0 additions & 43 deletions ch09/ex9_41_42.cpp

This file was deleted.

0 comments on commit 9b355f0

Please sign in to comment.