Skip to content

Commit 32983f6

Browse files
committed
统一示例风格
1 parent 24a7b0c commit 32983f6

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

libs/cpp.wiki

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“
290290
<source lang="cpp">
291291
&#35;include <iostream>
292292
&#35;include <boost/format.hpp>
293+
293294
using std::cout;
294295
using boost::format;
295296

@@ -347,6 +348,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“
347348
代码示例——基于正则式进行匹配和替换
348349
<source lang="cpp">
349350
&#35;include <boost/regex.hpp>
351+
350352
using std::string;
351353
using namespace boost;
352354

@@ -384,6 +386,7 @@ Home:[https://github.com/google/re2]
384386
代码示例——基于正则式进行匹配
385387
<source lang="cpp">
386388
&#35;include <re2/re2.h>
389+
387390
int i;
388391
string s;
389392
assert(RE2::FullMatch("test:1234", "(\\w+):(\\d+)", &s, &i));
@@ -719,11 +722,13 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,用来辅助
719722
&#35;include <iostream>
720723
&#35;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
&#35;include <iostream>
742747
&#35;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
&#35;include <stdio.h> /* for printf */
13171323
&#35;include <stdlib.h> /* for exit */
13181324
&#35;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
&#35;include <stdio.h>
14111418
&#35;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
&#35;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
&#35;include <stdio.h>
17731780
&#35;include <stdlib.h>
17741781
&#35;include <unistd.h>
1775-
17761782
&#35;include <event.h>
17771783
&#35;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
&#35;include <bson.h>
23202326
&#35;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
&#35;include <boost/numeric/ublas/matrix.hpp>
34163422
&#35;include <boost/numeric/ublas/io.hpp>
34173423

3424+
using namespace std;
34183425
using namespace boost::numeric::ublas;
3426+
34193427
vector<double> v(2);
34203428
v(0) = 1; v(1) = 2;
34213429

@@ -3424,7 +3432,7 @@ m(0,0) = 0; m(0,1) = 1;
34243432
m(1,0) = 2; m(1,1) = 3;
34253433

34263434
vector<double> v2 = prod(m, v);
3427-
std::cout << v2 << std::endl;
3435+
cout << v2 << endl;
34283436
</source>
34293437

34303438
<h4>Blitz++</h4>

0 commit comments

Comments
 (0)