zoukankan      html  css  js  c++  java
  • strings <---> numbers

    • strings ---> numbers
       1 #include "stdafx.h"
      2 #include <iostream>
      3 #include <sstream>
      4 using namespace std;
      5
      6 int _tmain(int argc, _TCHAR* argv[])
      7 {
      8 stringstream os;
      9 os << "12345 67.89"; // insert a string of numbers into the stream
      10 int nValue;
      11 double dValue;
      12
      13 os >> nValue >> dValue;
      14
      15 cout << nValue << " " << dValue << endl;
      16
      17 return 0;
      18 }
    • numbers ---> strings
       1 #include "stdafx.h"
      2 #include <iostream>
      3 #include <sstream>
      4 using namespace std;
      5
      6 int _tmain(int argc, _TCHAR* argv[])
      7 {
      8 stringstream os;
      9
      10 int nValue = 12345;
      11 double dValue = 67.89;
      12 os << nValue << " " << dValue;
      13
      14 string strValue1, strValue2;
      15 os >> strValue1 >> strValue2;
      16
      17 cout << strValue1 << " " << strValue2 << endl;
      18
      19 return 0;
      20 }
  • 相关阅读:
    linux 第五天
    linux 第四天
    二进制 位运算
    二进制
    java 方法的调用过程
    Linux 第三天
    Linux 第二天
    Linux
    学习了半个多月的TankGame
    学习第一天(spring)
  • 原文地址:https://www.cnblogs.com/dahai/p/2277938.html
Copyright © 2011-2022 走看看