首页 > 代码库 > c++ string char* 获取输入值的区别

c++ string char* 获取输入值的区别

#include <iostream>  #include <string>  using namespace std;      void reverseStr(string &s,int begin,int end){            while (begin < end) {          char temp = s[begin];          s[begin] = s[end];          s[end] = temp;          begin++;          end--;      }  }      int main(){         //对于char* / char[]      char s[1001];      cout<<"Please input char[]:"<<endl;      cin.getline(s, 1000);//iostream下的函数, 第二个参数表示允许的最大输入长度      cout<<"Output:"<<endl<<s<<endl<<strlen(s)<<endl;         //对于string      string ss;      cout<<"Please input string:"<<endl;      getline(cin, ss); //这个getline函数在<string>头文件下      cout<<"Output:"<<endl<<ss<<endl<<ss.length()<<endl; 		int i=0;	int j=0;	int icount=0;	int jcount=0;	while(s[i]!=‘\0‘){		cout<<s[i]<<icount<<" ";		i++;		icount++;	}	cout<<endl;	while(ss[j]!=‘\0‘){		cout<<s[j]<<jcount<<" ";		j++;		jcount++;	}	cout<<endl;	    return 0;  } 

  

c++ string char* 获取输入值的区别