Almost everyone who has just learned a programming language will write a hello world Procedure of .
c++ It's a complex language , So there are many different ways to do the same thing , We will not discuss whether this is a good phenomenon or a bad one . method 1
: original c Methods and classic c++ method #include <cstdio> #include <iostream> using namespace std; int
main() {printf("Hello world"); puts("Hello world"); cout << "Hello world" <<
endl;return 0; } method 2: Using macros to print Hello world #include <cstdio> #define
saySomething(sth) puts(#sth) int main() { return saySomething(Hello world); }
method3: Using iterators iterator To achieve output #include <iostream> #include <string> #include
<iterator> #include <algorithm> int main() { std::string str("Hello world"); std
::copy(std::begin(str),std::end(str), std::ostream_iterator<char>(std::cout, ""
));return 0; } method 4: Using file name macro to realize Hello world The key is to name the source code file Hello world.cpp
#include <string> #include <iostream> int main() { std::string
fileName(__FILE__);std::cout << fileName.substr(0, fileName.find("."))<< std
::endl;return 0; }
To be continued ...
Technology
Daily Recommendation