String int 互相转换
//C
std::string str;
int i = atoi(str.c_str());
//C++
std::string str;
int i = std::stoi(str);
//同样, 可以使用 stol(long), stof(float), stod(double) 等.
string temp = to_string (int val)
STL
Stack
#include<iostream>
#include<stack>
using namespace std;
int main(void)
{
stack<double>s;//定义一个栈
for(int i=0;i<10;i++)
s.push(i);
while(!s.empty())
{
printf("%lf\n",s.top());
s.pop();
}
cout<<"栈内的元素的个数为:"<<s.size()<<endl;
return 0;
}
Queue
#include<iostream>
#include<queue>
#include<stdlib.h>
using namespace std;
class T
{
public:
int x,y,z;
T(int a,int b,int c):x(a),y(b),z(c)
{
}
};
bool operator<(const T&t1,const T&t2)
{
return t1.z<t2.z;
}
int main(void)
{
priority_queue<T>q;
q.push(T(4,4,3));
q.push(T(2,2,5));
q.push(T(1,5,4));
q.push(T(3,3,6));
while(!q.empty())
{
T t=q.top();
q.pop();
cout<<t.x<<" "<<t.y<<" "<<t.z<<endl;
}
system("Pause");
return 1;
}