To download the code, click here

01: #include <iostream>
02: using std::cin;
03: using std::cout;
04: using std::endl;
05: 
06: #include <string>
07: using std::string;
08: 
09: #include <vector>
10: using std::vector;
11: 
12: #include <iterator>
13: using std::ostream_iterator;
14: 
15: #include <algorithm>
16: using std::copy;
17: using std::fill;
18: 
19: int main (int argc, char  *argv[])
20: {
21:         //c style string
22:         char *s = "foo";
23:         
24:         //c/c++ array
25:         int b[10];
26:         
27:         string s1 = "this is a C++ string";
28:         string s2 = "this is another string";
29:         
30:         if (s1 != s2){
31:                 cout << s1 << " is not equal to " << s2 << endl;
32:         }
33:         
34:         //to get the length of a string:
35:         //s1.size()/s1.length()
36:         
37:         //string concatenation
38:         string s3 = s1 + s2;
39:         
40:         //substrings:
41:         int start = 0;
42:         int length = 5;
43:         string s4 = s1.substr(start, length);
44:         
45:         //get specific character
46:         char c = s4.at(4);
47:         
48:         //find first instance of a substr:
49:         int pos = s4.find("string");
50:         //returns string::npos if not found
51:         
52:         if (pos != string::npos){
53:                 //we found it, so do something with it
54:         }
55:         
56:         cout << "Please enter 10 integers" << endl;
57:         vector<int> v;
58:         for (int i = 0; i < 10; ++i){
59:                 int j;
60:                 cin >> j;
61:                 v.push_back(j);
62:         }
63:         
64:         //how many items in the vector:
65:         cout << v.size() << endl;
66:         
67:         //ITERATORS
68:         //binky pointer video
69:         
70:         //print out a vector using iterators
71:         for (vector<int>::iterator i = v.begin(); i != v.end(); ++i){
72:                 cout << *i << endl;
73:         }
74: 
75:         fill(v.begin(), v.end(), 41);
76: 
77:         //print out a vector using iterators, in another way...backwards
78:         copy(v.rbegin(), v.rend(), ostream_iterator<int>(cout, "\n"));
79:         
80:         return EXIT_SUCCESS;
81: }
82: 
83: 
84: 
85: 
86: 
87: 
88: 
89: