第二天第三个问题

发布时间 2023-04-13 19:08:57作者: 序章0

问题描述:编写上一个问题,但使用string对象而不是字符数组

解决思路:于上个问题相同

代码:

#include <iostream>
#include<cstring>
#include <string>
using namespace std;
int main()

{
string a;
string b= "done" ;
int ans = 0;
cout << "enter words:";
cout << endl;
for (;;)
{
cin>>a;
if (a==b)
break;
ans++;
}
cout << "you entered a total of ";
cout << ans;
cout << " words";
return 0;
}