新文章

2012年1月11日 星期三

[C++]輸出相反字串相關函式

兩種型式探討



String形式

#include <iostream>
#include <stdlib.h>
#include <string>
#include <algorithm>
using namespace std;

int main () {
  string str;
  cout<<"Enter a line of text:";
  cin>>str;
  reverse(str.begin(),str.end());
  cout<<str<<endl;

  system("PAUSE");
  return 0;
}




字元陣列型式

#include <stdlib.h>
#include <iostream.h>
#include <string.h>


int main()
{
     char s[]="abcd";
     strrev(s);
     cout<<s;
     system("PAUSE");
     return 0;
}

沒有留言:

張貼留言