开发者

C++11 to_string() function, where? [closed]

开发者 https://www.devze.com 2023-04-07 00:57 出处:网络
开发者_StackOverflow It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current
开发者_StackOverflow It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

See the N3242 Working Draft of C++11, chapter 21.5 Numeric Conversions.

There are some useful functions, such as string to_string(int val); mentioned but I don't understand how they're called. Can anyone give me an example please?


Those functions are in the header <string>. You just call them like any other function:

#include <string>
std::string answer = std::to_string(42);

GCC 4.5 already supports those functions, you just need to compile with the -std=c++0x flag.


Sure:

std::string s = std::to_string(123);  // now s == "123"

These functions use sprintf (or equivalent) internally.


They are called like any other function:

int number = 10;
std::string value;
value = std::to_string(number);
std::cout << value;

To call them you will need a C++ compiler that supports the draft recommendations (VS2010 and GCC4+ I think support them).

0

精彩评论

暂无评论...
验证码 换一张
取 消