积极答复者
请教一个简单的c++问题

问题
-
本人新学c++,请教大家,看看以下的这个程序为什么报错
#include<iostream> #include<string> #include<algorithm> using namespace std; void main() { int n; cin>>n; string *array=new string[n]; for(int k=0;k<n;k++) cin>>array[k]; for(int i=0;i<n;i++) reverse(array[i].begin,array[i].end); for(int j=0;j<n;j++) cout<<array[i]<<endl; }
错误信息为cannot deduce template argument as function argument is ambiguous。
reverse函数的具体用法是什么啊。我想将string串倒置。
这个程序为什么出错
答案
-
你自己对比一下吧
记得申请空间要释放
#include<iostream> #include<string> #include<algorithm> using namespace std; void main() { int n; cin>>n; string *strArray=new string[n]; for(int k=0;k<n;k++) cin>>strArray[k]; for(int i=0;i<n;i++) reverse(strArray[i].begin(), strArray[i].end()); for(int j=0;j<n;j++) cout<<strArray[j]<<endl; delete[] strArray; system("pause"); }
全部回复
-
你自己对比一下吧
记得申请空间要释放
#include<iostream> #include<string> #include<algorithm> using namespace std; void main() { int n; cin>>n; string *strArray=new string[n]; for(int k=0;k<n;k++) cin>>strArray[k]; for(int i=0;i<n;i++) reverse(strArray[i].begin(), strArray[i].end()); for(int j=0;j<n;j++) cout<<strArray[j]<<endl; delete[] strArray; system("pause"); }
-
关于reverse函数的用法可以参考这里http://www.cplusplus.com/reference/algorithm/reverse/
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.