summaryrefslogtreecommitdiff
path: root/c,cc/split.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-15 03:50:12 +0200
committerPatrick Simianer <p@simianer.de>2014-06-15 03:50:12 +0200
commit258e1b92ebbfdebefabc120969ab87c3d8b75c3d (patch)
treeef4ab11fe0bf9d720cea23b35711358a8465feeb /c,cc/split.cc
parentcf3a29feb5887344b6633ead1b4b6d5657a15a4b (diff)
old c,cc examples
Diffstat (limited to 'c,cc/split.cc')
-rw-r--r--c,cc/split.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/c,cc/split.cc b/c,cc/split.cc
new file mode 100644
index 0000000..e01ad64
--- /dev/null
+++ b/c,cc/split.cc
@@ -0,0 +1,55 @@
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <vector>
+
+using namespace std;
+
+
+int main(void)
+{
+ string s("a\tb\tc\td");
+ string::iterator it = s.begin();
+ char d = '\t';
+ string tmp;
+ size_t parts = 4;
+ size_t c = 0;
+ while(true) {
+ if (parts > 0 && c == parts-1) {
+ while(it != s.end()) {
+ tmp += *it;
+ it++;
+ }
+ cout << tmp << endl;
+ break;
+ }
+ if (it == s.end()) { cout << tmp << endl; break; }
+ if (*it != d) tmp += *it;
+ else {
+ cout << tmp << endl;
+ tmp.clear();
+ c++;
+ }
+ it++;
+ }
+
+ cout << "---" << endl;
+
+ stringstream ss(s);
+ string si;
+ parts = 0;
+ c = 0;
+
+ while(true)
+ {
+ if (parts > 0 && c == parts-1) {
+ getline(ss, si);
+ cout << si << endl;
+ break;
+ }
+ if(!getline(ss, si, '\t')) break;
+ cout << si << endl;
+ c++;
+ }
+}
+