中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

stringstream 字符串的格式化數據提取

發布時間:2020-08-02 07:31:33 來源:網絡 閱讀:848 作者:fengyuzaitu 欄目:編程語言

1 格式化字符串,提取其中的各種數據類型
void test1()
{
std::string strCompleteMsg = "0R1,Dn=236D,Dm=283D,Dx=031D,Sn=0.0M,Sm=1.0M,Sx=2.2M/r/n";
for (int i = 0; i < strCompleteMsg.length(); i++)
{
if ((',' == strCompleteMsg[i]) || ('D' == strCompleteMsg[i]) || ('=' == strCompleteMsg[i]) || ('M' == strCompleteMsg[i]) || ('S' == strCompleteMsg[i]))
{
strCompleteMsg[i] = ' ';
}
}
int nDn = 0, nDm = 0, nDx = 0;
float fSn = 0, fSm = 0, fSx = 0;
std::string str1;
char str2, str3, str4, str5, str6;

std::stringstream ss;
ss << strCompleteMsg;
ss >> str1;
ss >> str1;
ss >> nDn;
ss >> str1;
ss >> nDm;
ss >> str1;
ss >> nDx;
ss >> str1;
ss >> fSn;
ss >> str1;
ss >> fSm;
ss >> str1;
ss >> fSx;

}

void test2()
{
std::string strCompleteMsg = "DSC,6,2,0.33,0.01,0.08,0.28,0.2887,0.234";
for (int i = 0; i < strCompleteMsg.length(); i++)
{
if (',' == strCompleteMsg[i])
{
strCompleteMsg[i] = ' ';
}
}
std::stringstream ss;
ss << strCompleteMsg;

std::string strDsc;

int nSurfaceStatus = 0;
int nWarning = 0;
float fLevelOfGrip = 0, fAmountOfWater = 0, fAmountOfIce = 0, fAmountOfSnow = 0;

ss >> strDsc;
ss >> nSurfaceStatus;
ss >> nWarning;
ss >> fLevelOfGrip;
ss >> fAmountOfWater;
ss >> fAmountOfIce;
ss >> fAmountOfSnow;

}

2 整型與字符串之間的轉換
#include <sstream>
#include <string>

void Int2Str(int nNumber, std::string &strNumber)
{
stringstream stream;
stream << nNumber;
strNumber = stream.str();
}

void Str2Int(const std::string &strNumber, int &nNumber)
{
stringstream stream(strNumber);
stream >> nNumber;
}

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

阿拉善盟| 盐山县| 武定县| 宾阳县| 沾化县| 台北市| 遂平县| 西昌市| 武定县| 灵丘县| 观塘区| 六枝特区| 乃东县| 雅安市| 竹溪县| 德昌县| 鹿邑县| 和静县| 宜宾县| 库伦旗| 广宁县| 安丘市| 冕宁县| 出国| 黎城县| 绥棱县| 芦山县| 阿坝县| 南郑县| 轮台县| 涞源县| 玉田县| 克东县| 辽阳县| 报价| 凉城县| 鄂托克旗| 运城市| 彭水| 长寿区| 天峨县|