[問題] stringstream內有數字和字元
請教各位版上大大
當stringstream裡有int和
char型別的資料
要怎麼各別輸出呢?
以下是我的程式
#include <iostream>
#include <string>
#include <sstream>.
using namespace std;
int main()
{
int a = 92;
string b = 'b';
stringstream ss;
ss << a;
ss << b;
return 0;
}
如果我額外用一個string temp;
temp = ss.str();
cout << temp;
如此一來 會直接輸出92b 且92會變成char而不是int
有什麼方法可以輸出
92b 且92是原來的int b是原來的char型別
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.73.61.247
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1479444262.A.B21.html
※ 編輯: cchou0114 (42.73.61.247), 11/18/2016 12:45:08
→
11/18 12:48, , 1F
11/18 12:48, 1F
→
11/18 12:52, , 2F
11/18 12:52, 2F
→
11/18 12:52, , 3F
11/18 12:52, 3F
※ 編輯: cchou0114 (42.73.61.247), 11/18/2016 12:53:55
→
11/18 13:28, , 4F
11/18 13:28, 4F
→
11/18 13:38, , 5F
11/18 13:38, 5F
→
11/18 13:38, , 6F
11/18 13:38, 6F
→
11/18 14:02, , 7F
11/18 14:02, 7F
→
11/18 14:14, , 8F
11/18 14:14, 8F
→
11/18 14:17, , 9F
11/18 14:17, 9F
→
11/18 15:34, , 10F
11/18 15:34, 10F
→
11/18 15:35, , 11F
11/18 15:35, 11F
→
11/18 15:54, , 12F
11/18 15:54, 12F
→
11/18 15:54, , 13F
11/18 15:54, 13F
→
11/18 15:57, , 14F
11/18 15:57, 14F
→
11/18 16:02, , 15F
11/18 16:02, 15F
→
11/18 16:03, , 16F
11/18 16:03, 16F
→
11/18 18:20, , 17F
11/18 18:20, 17F
→
11/18 18:20, , 18F
11/18 18:20, 18F