alg0rith

Evolution of a C++ Programmer

May 28th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. Evolution of a Sepples Programmer
  2.  
  3. Learned basic C++ from an inadequate tutorial.
  4.  
  5. #include <iostream.h>
  6. using namespace std; // thanks, joe
  7. void main(int argc, char** argv) {
  8. cout << "Hello, world!" << endl;
  9. }
  10.  
  11. Learned basic C++ from a slightly better tutorial.
  12.  
  13. #include <iostream>
  14. using namespace std;
  15. int main(int argc, char* argv[]) {
  16. cout << "Hello, world!" << endl;
  17. return 0;
  18. }
  19.  
  20. Learned about namespace pollution.
  21.  
  22. #include <iostream>
  23. int main(int argc, char* argv[]) {
  24. std::cout << "Hello, world!" << std::endl;
  25. return 0;
  26. }
  27.  
  28. Learned about classes.
  29.  
  30. #include <iostream>
  31. #include <string.h>
  32. class Hello {
  33. private:
  34. char* msg;
  35. public:
  36. Hello() {
  37. this->msg = strdup("Hello, world!");
  38. }
  39. ~Hello() {
  40. delete this->msg;
  41. }
  42. char* hello() {
  43. return this->msg;
  44. }
  45. };
  46. int main(int argc, char* argv[]) {
  47. Hello* hello = new Hello();
  48. std::cout << hello->hello() << std::endl;
  49. delete hello;
  50. return 0;
  51. }
  52.  
  53. Learned about the C++ string container.
  54.  
  55. #include <iostream>
  56. #include <string>
  57. class Hello {
  58. private:
  59. std::string msg;
  60. public:
  61. Hello() {
  62. this->msg = "Hello, world!";
  63. }
  64. std::string hello() {
  65. return this->msg;
  66. }
  67. };
  68. int main(int argc, char* argv[]) {
  69. Hello hello;
  70. std::cout << hello.hello() << std::endl;
  71. return 0;
  72. }
  73.  
  74. Found out about the STL.
  75.  
  76. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/bits/ios_base.h: In copy constructor ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:
  77. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/bits/ios_base.h:783: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
  78. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/iosfwd:52: error: within this context
  79. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/iosfwd: In copy constructor ‘std::basic_ostream<char, std::char_traits<char> >::basic_ostream(const std::basic_ostream<char, std::char_traits<char> >&)’:
  80. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/iosfwd:61: note: synthesized method ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’ first required here
  81. test.cpp: In function ‘int main(int, char**)’:
  82. test.cpp:7: note: synthesized method ‘std::basic_ostream<char, std::char_traits<char> >::basic_ostream(const std::basic_ostream<char, std::char_traits<char> >&)’ first required here
  83. test.cpp:7: error: initializing argument 3 of ‘_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Funct = std::basic_ostream<char, std::char_traits<char> >]’
  84. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/bits/stl_algo.h: In function ‘_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Funct = std::basic_ostream<char, std::char_traits<char> >]’:
  85. test.cpp:7: instantiated from here
  86. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/bits/stl_algo.h:3791: error: no match for call to ‘(std::basic_ostream<char, std::char_traits<char> >) (char&)’
  87.  
  88. Mastered the basic containers of the STL.
  89.  
  90. #include <iostream>
  91. #include <string>
  92. #include <vector>
  93. int main(int argc, char* argv[]) {
  94. std::string hello = "Hello, world!";
  95. std::vector<char> v;
  96. for (unsigned int j = 0; j < hello.length(); ++j) {
  97. v.push_back(hello[j]);
  98. }
  99. std::vector<char>::iterator i;
  100. for (i = v.begin(); i != v.end(); ++i) {
  101. std::cout << *i;
  102. }
  103. std::cout << std::endl;
  104. return 0;
  105. }
  106.  
  107. Mastered the STL.
  108.  
  109. #include <iostream>
  110. #include <string>
  111. #include <algorithm>
  112. class printc { public: void operator() (char c) { std::cout << c; } };
  113. int main(int argc, char* argv[]) {
  114. std::string hello = "Hello, world!";
  115. std::for_each(hello.begin(), hello.end(), printc());
  116. std::cout << std::endl;
  117. return 0;
  118. }
  119.  
  120. Read the C++ FAQ Lite and realized C++ mastery is impossible.
  121.  
  122. #include <iostream>
  123. int main(int argc, char* argv[]) {
  124. std::cout << "Hello, world!" << std::endl;
  125. return 0;
  126. }
  127.  
  128. Read the C++ FQA Lite.
  129.  
  130. #include <stdio.h>
  131. int main(int argc, char* argv[]) {
  132. printf("Hello, world!\n");
  133. return 0;
  134. }
  135.  
  136. Heard of 4chan and wound up in /b/.
  137.  
  138. HAI
  139. CAN HAS STDIO?
  140. VISIBLE "HAI WORLD!"
  141. KTHXBYE
  142.  
  143. Found a replacement for /b/ after finding it overrun by ``cancer'' and ``newfags.''
  144.  
  145. One word, the forced indentation of code. Thread over. Also, read SICP!
  146.  
  147. Read SICP after months of telling people to read SICP.
  148.  
  149. (display "Hello, world!")
  150. (newline)
  151.  
  152. Achieved Satori after re-reading SICP every day for many years.
  153.  
  154. void main() { puts("Hello, world!"); }
Advertisement
Add Comment
Please, Sign In to add comment