整数转字符串

来源:互联网 发布:windows网络编程模型 编辑:程序博客网 时间:2024/05/01 22:59

知识点:

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;}


方法二:

#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;}


0 0
原创粉丝点击