Skip to content

Commit

Permalink
strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ash committed Feb 8, 2017
1 parent a4e272c commit 42c7966
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 5 deletions.
39 changes: 39 additions & 0 deletions 047.cpp
@@ -0,0 +1,39 @@
#include <iostream>
#include <set>

using namespace std;

int main() {
set<char> s;

s.insert('a');
s.insert('b');
s.insert('a');
s.insert('c');

for (set<char>::const_iterator iter = s.begin(); iter != s.end(); iter++) {
cout << *iter << endl;
}

cout << "\n";

s.erase('b');

for (set<char>::const_iterator iter = s.begin(); iter != s.end(); iter++) {
cout << *iter << endl;
}

if (s.find('a') != s.end()) {
cout << "a exists" << "\n";
}
else {
cout << "a does not exist" << "\n";
}

if (s.find('b') != s.end()) {
cout << "b exists" << "\n";
}
else {
cout << "b does not exist" << "\n";
}
}
16 changes: 16 additions & 0 deletions 048.cpp
@@ -0,0 +1,16 @@
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
map<string, double> m;

m["pi"] = 3.14;
m["e"] = 2.71;

for (map<string, double>::const_iterator iter = m.begin(); iter != m.end(); iter++) {
cout << iter->first << '=' << iter->second << "\n";
}
}
28 changes: 28 additions & 0 deletions 049.cpp
@@ -0,0 +1,28 @@
#include <iostream>
#include <string>

using namespace std;

int main() {
string s = "abcdef";

for (string::const_iterator i = s.begin(); i != s.end(); i++)
cout << *i << "\n";

for (auto i = s.begin(); i != s.end(); i++)
cout << *i << "\n";

for (auto x : s)
cout << x << "\n";

cout << s.length() << ' ' << s.size() << "\n";

for (int i = 0; i != s.length(); i++)
cout << s[i] << "\n";

if (s.find('x') != string::npos) cout << "x in string\n";
else cout << "x not in string\n";

if (s.find('e') != string::npos) cout << "e in string\n";
else cout << "e not in string\n";
}
28 changes: 28 additions & 0 deletions 050.cpp
@@ -0,0 +1,28 @@
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
cout << setw(10) << 8 << endl;
cout << 9 << endl;

cout.width(10);
cout << 8 << endl;
cout << 9 << endl;

cout << setprecision(4) << 3.1415926 << "\n";

cout << setw(10) << setfill('_') << "Yo" << endl;
cout << setw(10) << setfill('_') << "Yo\n";

cout << setbase(16) << 254 << endl;

cout << hex << 254 << endl;
cout << setiosflags(std::ios::showbase | std::ios::uppercase) << 254 << endl;

cout << 123 << endl;

cout << resetiosflags(std::ios::hex | std::ios::showbase | std::ios::uppercase) << 254 << endl;
cout << 123 << endl;
}
26 changes: 21 additions & 5 deletions README.txt
Expand Up @@ -274,12 +274,28 @@ STL
pop
Associative containers
set
insert
erase
find
map




strings
iter->first, iter->second
<string>
iterators (and rbegin, begin, end, rend)
auto instead of iterators
for (auto x : s)
size, length
[], at
+, +=
c_str
find, string::npos
<iomanip>
setw
setfill
setbase
setprecision
> exersise: print table
hex
setiosflags/resetiosflags (std::ios::showbase | std::ios::uppercase);

io
iomanips
Expand Down

0 comments on commit 42c7966

Please sign in to comment.