码迷,mamicode.com
首页 > 其他好文 > 详细

整数转字符串

时间:2014-06-08 05:42:23      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:c++整数转字符串

知识点:

c++中栈的操作

方法一:

#include "stdafx.h"
#include <iostream>
#include <stack>
using namespace std;

int main(int argc, char** argv)
{
	stack<char> s;

	int num=1234050;
	int temp;
	char ch;

	while(num!=0)
	{
		temp=num%10;
		ch=temp+'0';
		num/=10;
		s.push(ch);
	}

	cout<<"The number is:"<<endl;
	while(!s.empty())
	{
		ch=s.top();
		cout<<ch;
		s.pop();
	}

	cout<<endl;
	system("pause");
    return 0;
}
bubuko.com,布布扣


方法二:

#include "stdafx.h"
#include <iostream>
using namespace std;

int main(int argc, char** argv)
{
	int  num=1234050;
	char string[8];

	itoa(num,string,10);
	cout<<string<<endl;

	system("pause");
    return 0;
}
bubuko.com,布布扣

整数转字符串,布布扣,bubuko.com

整数转字符串

标签:c++整数转字符串

原文地址:http://blog.csdn.net/cjc211322/article/details/29176993

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!