知识点:
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; }
原文:http://blog.csdn.net/cjc211322/article/details/29176993