forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
13 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
//! @Alan | ||
//! @Alan @pezy | ||
//! | ||
//! Exercise 9.24: | ||
//! Write a program that fetches the first element in a vector using at, | ||
//! the subscript operator, front, and begin. Test your program on an empty vector. | ||
//! | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
#include <deque> | ||
#include <list> | ||
|
||
|
||
int main() | ||
{ | ||
std::vector<int> v; | ||
std::cout | ||
//<< v.at(0); //an exception was thrown | ||
//<< v[0]; //nothing happened | ||
//<< v.front(); //nothing happened | ||
<< *v.begin(); //nothing happened | ||
std::cout << v.at(0); // terminating with uncaught exception of type std::out_of_range | ||
std::cout << v[0]; // Segmentation fault: 11 | ||
std::cout << v.front(); // Segmentation fault: 11 | ||
std::cout << *v.begin(); // Segmentation fault: 11 | ||
return 0; | ||
} |