原博文鏈接在我的官方網站,網址是:http://www.aobosir.com/blog/2017/02/07/cpp-string-fusion-and-int-to-string/
字符串融合
#include <string>
std::string str = std::string("../pairAlginClass/capture0001") + std::string(".pcd");
或者
std::string str(std::string("../pairAlginClass/capture0001") + std::string(".pcd"));
string 與 int 之間最簡單的轉換方法
下面的代碼,我們需要使用C++11,C++11裏面有std::to_string()
方法。
#include <string>
int i = 123;
std::string str = std::to_string(i);
給項目添加C++11:
如果是CMakeLists.txt
文件的項目。就在CMakeLists.txt
文件中添加:
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
如果是Qt
項目的,就在.pro
文件裏面添加:
CONFIG += c++11
參考網站:
更多精彩的博文,請訪問:http://www.aobosir.com/