天天看点

关于字符串类型的一些语句细节

关于字符串类型的一些语句细节
类型 输入函数;——计算字符串长度
char类型 fgets(变量名,1999,stdin);——strlen(变量名)
String类型 Getling(cin,变量名);——变量名.size()
#include <string.h>
char*p=NULL;                                          
p=new char[100];                                    
cin>>p; 
           
#include <string.h>
char str[2000];
fgets(str,1999,stdin);
 cout << strlen(str) << endl;//strlen只能用char*做参数,且必须是以''\0''结尾的。
           
#include <iostream>
using namespace std;
#include <string> 
string   str2;    
getline(cin, str2);  
 cout << str2.size() << endl;     
           

继续阅读