zoukankan      html  css  js  c++  java
  • C++ 中 int 转string, 以及10进制转2进制

    感谢:http://blog.csdn.net/xiaofei2010/article/details/7434737

      以及:http://www.cnblogs.com/nzbbody/p/3504199.html

    1. int转string(更多参见:http://www.cnblogs.com/nzbbody/p/3504199.html)

     1 #include <iostream>
     2 #include <sstream>
     3 using namespace std;
     4 
     5 int main()      {
     6     int aa = 30;
     7     stringstream ss;
     8     ss<<aa; 
     9     string s1 = ss.str();
    10     cout<<s1<<endl; // 30
    11 
    12     string s2;
    13     ss>>s2;
    14     cout<<s2<<endl; // 30
    15        
    16     system("pause");
    17     return 0;
    18 }

    2.10进制转2进制(更多参见:http://blog.csdn.net/xiaofei2010/article/details/7434737)

     1 //十进制转二进制
     2 #include<iostream>
     3 using namespace std;
     4 
     5 void printbinary(const unsigned int val)
     6 {
     7     for(int i = 16; i >= 0; i--)    {
     8         if(val & (1 << i))
     9             cout << "1";
    10         else
    11             cout << "0";
    12     }
    13 }
    14 
    15 int main()
    16 {
    17     printbinary(1024);
    18     return 0;
    19 }
  • 相关阅读:
    # beta冲刺(2/7)
    # beta冲刺(1/7)
    福大软工 · 最终作业
    软工随笔纪实 《个人日志》
    beta答辩总结
    beta冲刺(6/7)
    (beta冲刺5/7)
    beta冲刺(4/7)
    beta冲刺(3/7)
    beta冲刺(2/7)
  • 原文地址:https://www.cnblogs.com/QingHuan/p/5054515.html
Copyright © 2011-2022 走看看