字符串输入的几种方式

字符串配套

1,以字符数组输入

#include 
#include 
const int M = 1e5 + 10;
char str[M]="";
cin.getline(str,M);
int l = strlen(str);
for(int i=0;i

2.字符串输入

#include 
string str;
//当前面还需要输入其他数据,则要清除
getchar();
getline(cin,str);
int l = str.size();
for(int i=0;i

或者用vector

#include 


vectorv;
for(int i=0;i

或者用getchar()

	char a[100007];
	a[0] = getchar();
	int cnt = 1;
	while (a[cnt-1] != '.')
	{
		a[cnt++] = getchar();
	}
	int l = strlen(a); 

//有的时候字符串没有结束标志,则自己可以手动加一个结束标志,比如判断英文句子中单词的个数

3581. 单词识别 - AcWing题库 

 再或者用c语言的gets

#include 
using namespace std;
int main()
{

gets(x);
int l=stlen(x);
for(int i=0;i

你可能感兴趣的:(笔记,c++)