@@ -290,6 +290,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“
290290<source lang="cpp">
291291#include <iostream>
292292#include <boost/format.hpp>
293+
293294using std::cout;
294295using boost::format;
295296
@@ -347,6 +348,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“
347348代码示例——基于正则式进行匹配和替换
348349<source lang="cpp">
349350#include <boost/regex.hpp>
351+
350352using std::string;
351353using namespace boost;
352354
@@ -384,6 +386,7 @@ Home:[https://github.com/google/re2]
384386代码示例——基于正则式进行匹配
385387<source lang="cpp">
386388#include <re2/re2.h>
389+
387390int i;
388391string s;
389392assert(RE2::FullMatch("test:1234", "(\\w+):(\\d+)", &s, &i));
@@ -719,11 +722,13 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,用来辅助
719722#include <iostream>
720723#include <boost/function.hpp>
721724
722- boost::function<int(const char*)> f = std::atoi;
723- std::cout << f("42") << '\n';
725+ using namespace std;
726+
727+ boost::function<int(const char*)> f = atoi;
728+ cout << f("42") << '\n';
724729
725- f =std:: strlen;
726- std:: cout << f("42") << '\n';
730+ f = strlen;
731+ cout << f("42") << '\n';
727732</source>
728733
729734<h4>Boost.Lambda</h4>
@@ -741,10 +746,11 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“
741746#include <iostream>
742747#include <boost/lambda/lambda.hpp>
743748
744- std::vector<int> v;
749+ using namespace std;
750+
751+ vector<int> v;
745752// 此处填充 v
746- std::for_each(v.begin(), v.end(),
747- std::cout << boost::lambda::_1 << "\n");
753+ for_each(v.begin(), v.end(), cout << boost::lambda::_1 << "\n");
748754</source>
749755
750756== 3.4 元编程(Metaprogramming) ==
@@ -1316,7 +1322,8 @@ Links:[https://en.wikipedia.org/wiki/Getopt Wikipedia]
13161322#include <stdio.h> /* for printf */
13171323#include <stdlib.h> /* for exit */
13181324#include <unistd.h> /* for getopt */
1319- int main(int argc, char** argv)
1325+
1326+ int main(int argc, char* argv[])
13201327{
13211328 int digit_optind = 0;
13221329 int aopt = 0, bopt = 0;
@@ -1410,7 +1417,7 @@ Links:[https://en.wikipedia.org/wiki/Pcap Wikipedia]
14101417#include <stdio.h>
14111418#include <pcap.h>
14121419
1413- int main(int argc, char* argv[] )
1420+ int main()
14141421{
14151422 pcap_t* handle; /* Session handle */
14161423 char* dev; /* The device to sniff on */
@@ -1680,7 +1687,7 @@ ZeroMQ 是一个轻量级、跨平台的开源库,提供了高性能、异步
16801687<source lang="cpp">
16811688#include <zhelpers.hpp>
16821689
1683- int main(int argc, char* argv[] )
1690+ int main()
16841691{
16851692 zmq::context_t context(1);
16861693
@@ -1772,7 +1779,6 @@ Links:[https://en.wikipedia.org/wiki/Libevent Wikipedia] [https://zh.wikipedia
17721779#include <stdio.h>
17731780#include <stdlib.h>
17741781#include <unistd.h>
1775-
17761782#include <event.h>
17771783#include <evhttp.h>
17781784
@@ -1785,7 +1791,7 @@ void generic_request_handler(struct evhttp_request* req, void* arg)
17851791 evbuffer_free(return_buffer);
17861792 }
17871793
1788- int main(int argc, char** argv )
1794+ int main()
17891795{
17901796 short http_port = 8080;
17911797 char* http_addr = "127.0.0.1";
@@ -2319,7 +2325,7 @@ MongoDB 前面已经介绍过。这是其官方提供的 API。
23192325#include <bson.h>
23202326#include <mongoc.h>
23212327
2322- int main(int argc, char* argv[] )
2328+ int main()
23232329{
23242330 mongoc_init();
23252331
@@ -3415,7 +3421,9 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,实现了 BLA
34153421#include <boost/numeric/ublas/matrix.hpp>
34163422#include <boost/numeric/ublas/io.hpp>
34173423
3424+ using namespace std;
34183425using namespace boost::numeric::ublas;
3426+
34193427vector<double> v(2);
34203428v(0) = 1; v(1) = 2;
34213429
@@ -3424,7 +3432,7 @@ m(0,0) = 0; m(0,1) = 1;
34243432m(1,0) = 2; m(1,1) = 3;
34253433
34263434vector<double> v2 = prod(m, v);
3427- std:: cout << v2 <<std:: endl;
3435+ cout << v2 << endl;
34283436</source>
34293437
34303438<h4>Blitz++</h4>