String int 互相转换

  1. //C
  2. std::string str;
  3. int i = atoi(str.c_str());
  4. //C++
  5. std::string str;
  6. int i = std::stoi(str);
  7. //同样, 可以使用 stol(long), stof(float), stod(double) 等.
  8. string temp = to_string (int val)

STL

Stack

  1. #include<iostream>
  2. #include<stack>
  3. using namespace std;
  4. int main(void)
  5. {
  6. stack<double>s;//定义一个栈
  7. for(int i=0;i<10;i++)
  8. s.push(i);
  9. while(!s.empty())
  10. {
  11. printf("%lf\n",s.top());
  12. s.pop();
  13. }
  14. cout<<"栈内的元素的个数为:"<<s.size()<<endl;
  15. return 0;
  16. }

Queue

  1. #include<iostream>
  2. #include<queue>
  3. #include<stdlib.h>
  4. using namespace std;
  5. class T
  6. {
  7. public:
  8. int x,y,z;
  9. T(int a,int b,int c):x(a),y(b),z(c)
  10. {
  11. }
  12. };
  13. bool operator<(const T&t1,const T&t2)
  14. {
  15. return t1.z<t2.z;
  16. }
  17. int main(void)
  18. {
  19. priority_queue<T>q;
  20. q.push(T(4,4,3));
  21. q.push(T(2,2,5));
  22. q.push(T(1,5,4));
  23. q.push(T(3,3,6));
  24. while(!q.empty())
  25. {
  26. T t=q.top();
  27. q.pop();
  28. cout<<t.x<<" "<<t.y<<" "<<t.z<<endl;
  29. }
  30. system("Pause");
  31. return 1;
  32. }