Sunday, June 22. 2008
Learned basic C++ from an inadequate tutorial.
#include <iostream.h> using namespace std; // thanks, joe void main(int argc, char** argv) { cout << "Hello, world!" << endl; }
Learned basic C++ from a slightly better tutorial.
#include <iostream> using namespace std; int main(int argc, char* argv[]) { cout << "Hello, world!" << endl; return 0; }
Learned about namespace pollution.
#include <iostream> int main(int argc, char* argv[]) { std::cout << "Hello, world!" << std::endl; return 0; }
Learned about classes.
#include <iostream> #include <string.h> class Hello { private: char* msg; public: Hello() { this->msg = strdup("Hello, world!"); } ~Hello() { delete this->msg; } char* hello() { return this->msg; } }; int main(int argc, char* argv[]) { Hello* hello = new Hello(); std::cout << hello->hello() << std::endl; delete hello; return 0; }
Learned about the C++ string container.
#include <iostream> #include <string> class Hello { private: std::string msg; public: Hello() { this->msg = "Hello, world!"; } std::string hello() { return this->msg; } }; int main(int argc, char* argv[]) { Hello hello; std::cout << hello.hello() << std::endl; return 0; }
Found out about the STL.
/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> >&)’: /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 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.1/../../../../include/c++/4.3.1/iosfwd:52: error: within this context /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> >&)’: /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 test.cpp: In function ‘int main(int, char**)’: 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 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> >]’ /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> >]’: test.cpp:7: instantiated from here /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&)’
Mastered the basic containers of the STL.
#include <iostream> #include <string> #include <vector> int main(int argc, char* argv[]) { std::string hello = "Hello, world!"; std::vector<char> v; for (unsigned int j = 0; j < hello.length(); ++j) { v.push_back(hello[j]); } std::vector<char>::iterator i; for (i = v.begin(); i != v.end(); ++i) { std::cout << <strong>i; } std::cout << std::endl; return 0; }
Mastered the STL.
#include <iostream> #include <string> #include <algorithm> class printc { public: void operator() (char c) { std::cout << c; } }; int main(int argc, char</strong> argv[]) { std::string hello = "Hello, world!"; std::for_each(hello.begin(), hello.end(), printc()); std::cout << std::endl; return 0; }
Read the C++ FAQ Lite and realized C++ mastery is impossible.
#include <iostream> int main(int argc, char* argv[]) { std::cout << "Hello, world!" << std::endl; return 0; }
Read the C++ FQA Lite.
#include <stdio.h> int main(int argc, char* argv[]) { printf("Hello, world!\n"); return 0; }
Heard of 4chan and wound up in /b/.
HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
Found a replacement for /b/ after finding it overrun by ``cancer'' and ``newfags.''
One word, the forced indentation of code. Thread over. Also, read SICP!
Read SICP after months of telling people to read SICP.
(display "Hello, world!") (newline)
Achieved Satori after re-reading SICP every day for many years.
void main() { puts("Hello, world!"); }
(gefunden irgendwo auf 4chan, Dank an nion)
|