首页 > 其他 > 详细

整数转字符串

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

知识点:

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

整数转字符串

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!