楼主: ReneeBK
2028 9

C++ Cookbook [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4897份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49635 个
通用积分
55.6937
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2015-2-23 22:07:37 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
C++ Cookbook
Solutions and Examples for C++ Programmers



Book Description

The C++ Cookbook will make your path to mastery much shorter. This practical, problem-solving guide is ideal if you're an engineer, programmer, or researcher writing an application for one of the legions of platforms on which C++ runs. The algorithms provided in C++ Cookbook will jump-start your development by giving you some basicbuilding blocks that you don't have to develop on your own.

Less a tutorial than a problem-solver, the book addresses many of the most common problems you're likely encounter--whether you've beenprogramming in C++ for years or you're relatively new to the language.
Book Details
Publisher:O'Reilly Media
By:D. Ryan Stephens, Christopher Diggins,Jonathan Turkanis, Jeff Cogswell
ISBN:978-0-59600-761-4
Year:2005
Pages:594
Language:English
File size:3.9 MB
File format:PDF
eBook
Download:

本帖隐藏的内容

C++ Cookbook





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Cookbook Book Cook COO Programming practical provided develop shorter writing

本帖被以下文库推荐

沙发
richardchan001 发表于 2015-2-23 22:10:25
  1. Example 3-1. Converting number strings to numbers
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>

  5. using namespace std;

  6. long hex2int(const string& hexStr) {
  7.    char *offset;
  8.    if (hexStr.length() > 2) {
  9.       if (hexStr[0] == '0' && hexStr[1] == 'x') {
  10.          return strtol(hexStr.c_str(), &offset, 0);
  11.       }
  12.    }
  13.    return strtol(hexStr.c_str(), &offset, 16);
  14. }

  15. int main() {
  16.    string str1 = "0x12AB";
  17.    cout << hex2int(str1) << endl;
  18.    string str2 = "12AB";
  19.    cout << hex2int(str2) << endl;
  20.    string str3 = "QAFG";
  21.    cout << hex2int(str3) << endl;
  22. }
复制代码

已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

藤椅
xuruilong100 发表于 2015-2-23 22:14:46
  1. Example 3-2. Using lexical_cast
  2. #include <iostream>
  3. #include <string>
  4. #include <boost/lexical_cast.hpp>

  5. using namespace std;

  6. int main() {
  7.    string str1 = "750";
  8.    string str2 = "2.71";
  9.    string str3 = "0x7FFF";
  10.    try {
  11.       cout << boost::lexical_cast<int>(str1) << endl;
  12.       cout << boost::lexical_cast<double>(str2) << endl;
  13.       cout << boost::lexical_cast<int>(str3) << endl;
  14.    }
  15.    catch (boost::bad_lexical_cast& e) {
  16.       cerr << "Bad cast: " << e.what() << endl;
  17.    }
  18. }
复制代码

已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

板凳
accumulation 学生认证  发表于 2015-2-24 11:57:14 来自手机
  1. Example 3-3. Formatting a number as a string
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <sstream>

  6. using namespace std;

  7. int main() {

  8.    stringstream ss;

  9.    ss << "There are " << 9 << " apples in my cart.";
  10.    cout << ss.str() << endl;  // stringstream::str() returns a string
  11.                               // with the contents

  12.    ss.str("");                   // Empty the string
  13.    ss << showbase << hex << 16;  // Show the base in hexadecimal
  14.    cout << "ss = " << ss.str() << endl;

  15.    ss.str("");
  16.    ss << 3.14;
  17.    cout << "ss = " << ss.str() << endl;
  18. }
复制代码

已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

报纸
ouhaicourse 发表于 2015-3-2 21:08:03
  1. Example 3-4. Formatting integers as hexadecimal
  2. #include <iostream>
  3. #include <boost/format.hpp>

  4. using namespace std;
  5. using boost::format;
  6. using boost::io::str;
  7. using boost::io::format_error;

  8. int main() {

  9.    try {
  10.       format f("There are %1% ways %2% %3% %4%");

  11.       f % 3;
  12.       f % "to" % "do" % "this.";

  13.       cout << f << endl;

  14.       f.clear(); // Clear buffers to format something else

  15.       f.parse("Those cost $%d.");
  16.       f % 50;

  17.       cout << f << endl;

  18.       int x = 11256099;

  19.       string strx = str(format("%x") % x);
  20.       cout << strx << endl;
  21.    }
  22.    catch (format_error &e) {
  23.       cout << e.what() << endl;
  24.    }
  25. }
复制代码

已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

地板
ouhaicourse 发表于 2015-3-26 18:58:11
  1. Example 3-5. Validating a string number
  2. #include <iostream>
  3. #include <boost/lexical_cast.hpp>

  4. using namespace std;
  5. using boost::lexical_cast;
  6. using boost::bad_lexical_cast;

  7. template<typename T>
  8. bool isValid(const string& num) {

  9.    bool res = true;

  10.    try {
  11.       T tmp = lexical_cast<T>(num);
  12.    }
  13.    catch (bad_lexical_cast &e) {
  14.       res = false;
  15.    }

  16.    return(res);
  17. }

  18. void test(const string& s) {

  19.    if (isValid<int>(s))
  20.       cout << s << " is a valid integer." << endl;
  21.    else
  22.       cout << s << " is NOT a valid integer." << endl;

  23.    if (isValid<double>(s))
  24.       cout << s << " is a valid double." << endl;
  25.    else
  26.       cout << s << " is NOT a valid double." << endl;

  27.    if (isValid<float>(s))
  28.       cout << s << " is a valid float." << endl;
  29.    else
  30.       cout << s << " is NOT a valid float." << endl;
  31. }

  32. int main() {

  33.    test("12345");
  34.    test("1.23456");
  35.    test("-1.23456");
  36.    test(" - 1.23456");
  37.    test("+1.23456");
  38.    test("  1.23456  ");
  39.    test("asdf");
  40. }
复制代码

已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

7
Nicolle 学生认证  发表于 2015-6-1 07:11:28
提示: 作者被禁止或删除 内容自动屏蔽

8
Nicolle 学生认证  发表于 2015-6-1 07:13:08
提示: 作者被禁止或删除 内容自动屏蔽

9
Nicolle 学生认证  发表于 2015-6-1 07:14:57
提示: 作者被禁止或删除 内容自动屏蔽

10
Nicolle 学生认证  发表于 2015-6-1 07:17:24
提示: 作者被禁止或删除 内容自动屏蔽

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-25 18:17