Thứ Năm, 10 tháng 11, 2011

Convert int to std::string and long long to std::string

This is a long time i have never had a post. Today,  i will introduce you how to convert int and long long number to std::string.
When i join in a project about fuzzing browsers, i have to use a very large data type because i must count the number of requests to browsers and this course is continuous and it occures in a very and very long time.
So i think about long long data format. But when you send information to a browser, you must send a string request and if so, you need to convert long long to string before you send it.
When i got this problem, i found it on the internet in many famous websites, and the more websites i flurted, the more information i got. After that, i synthesized all information that i had and my work is well done.
In this topic i will introduce mainly about long long to std::string because "int" is a very popular data type.
"long long" is a data type that is used in C++, it is 64bits in length.  it's range in signed is from (-2^63) to (2^63 - 1) and in unsigned is from 0 to 2^64 - 1, so you can see it is a very and very range. This is the reason that i choose it for my project.
And now, i will introduce to convert this data type to std::string

+ Convert int to std::string



std::string IntToString(int number)
{
std::stringstream out;
out << number;
return out.str();
}

+ Convert long long to std::string


std::string LongLongToString(unsigned long long number)
{
std::stringstream out;
out << number;
return out.str();
}


To use two function, you need to declare some librabry, such as: <string> and <sstream>
I hope this information will help you in your work.
Thanks for visiting my blog.
Do your best, the rest will come!

Không có nhận xét nào:

Đăng nhận xét

Install Kubernetes using kubeadm with two nodes master & worker

Well come back for a long time my friends! Today I want to take a note about some basic knowledge about Kubernetes. I hope that it will...