int stringを切り替える
4079 ワード
教えを受けました。原文:http://blog.csdn.net/bluewrq851123/article/details/6443546
一、アスオを使う
説明:
itoa( 要点 value、 char *ストリングス 要点 ラジクス ); 最初のパラメータ:あなたが変換するポイント。 二つ目のパラメータ:変換後のchar*; 第三のパラメータ:あなたが変えたいのは進数です。
例:
[cpp] view plin copy///----------------------- /機能:C++ 要点 回転 ストリングス (atooを使う) /環境:VS 2005 ///----------------------- 〓〓include 「stdafx.h」 〓〓include using namespace std; int メール(int argc char* argv[] { 要点 n = 30; char c[10] itoa(n c, 2) cout << 「2-」 " << c << endl itoa(n c, 10) cout << "16-> " << c << endl itoa(n c, 16) cout << "10-> " << c << endl system("pause") return 0; } 出力:
一、アスオを使う
説明:
itoa( 要点 value、 char *ストリングス 要点 ラジクス ); 最初のパラメータ:あなたが変換するポイント。 二つ目のパラメータ:変換後のchar*; 第三のパラメータ:あなたが変えたいのは進数です。
例:
[cpp] view plin copy
2-> 11110
16-> 30
10-> 1e
. . .
、スプリングを う
ヘッダファイル include
:int sprintf(string format、mixed[args]…);
り : (streen)
を
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
%がパーセンテージ を して、 しません。
b を に します。
c は するASCII に されます。
d を10 に します。
f の は になります。
o は8 になります。
s を に します。
x を 16 に します。
X を 16 に します。
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= :
[c-sharp] view plin copy///----------------------- / :C++ ストリングス (スプリントを う) / :VS 2005 ///----------------------- 〓〓include "stdafx.h" 〓〓include 〓〓include <ストリングス using namespace std; int main() { n = 30; char c[20] sprintf(c 「%d」、 n) cout << c << endl sprintf(c 「%o」、 n) cout << c << endl sprintf(c 「%X」 n) cout << c << endl sprintf(c 「%c」、 n) cout << c << endl float f = 24.678; sprintf(c 「%f」、 f) cout << c << endl sprintf(c 「%2 f」、 f) cout << c << endl sprintf(c 「%d-%2 f」、 n, f) cout << c << endl system("pause") return 0; } :30
36
1E
// :
24.677999
24.68
30-24.68
、ストレスを う
:
[cpp] view plin copy///----------------------- / :C++ ストリングス (strigstreamを う) / :VS 2005 ///----------------------- 〓〓include 「stdafx.h」 〓〓include 〓〓include <ストリングス 〓〓include using namespace std; int main() { ストリングスストリーム stream a. = 100; float f = 23.56; stream << a. << “--”<< f ; ストリングス s = stream.str() cout << s << endl system("pause") return 0; } : . . .
、 のNB
//-------------------------------------------------------
// :
// http://baike.baidu.com/view/982195.htm?fr=ala0_1_1
// http://baike.baidu.com/view/1295144.htm?fr=ala0_1
// http://pppboy.blog.163.com/blog/static/3020379620085511954382/
//-------------------------------------------------------