...怎么设计c++程序使在键盘上输入任意一个字符串,输出该字符串,并统...
发布网友
发布时间:2024-01-18 14:39
我来回答
共3个回答
热心网友
时间:2024-03-07 21:33
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str[100];
cout<<"输入一个字符串"<<endl;
gets(str);
int i=0,k=0;
for(i=0;i<strlen(str);i++)
if(str[i]!=' ')
k++;
cout<<"输入的字符有"<<k<<"个"<<endl;
}
热心网友
时间:2024-03-07 21:31
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cin >> str;
cout << "输入的字符串为:" << str << " 长度为" << str.size() << endl;
return 0;
}
热心网友
时间:2024-03-07 21:31
#include "stdafx.h"//vc++6.0加上这一行.
#include <string>
#include <iostream>
using namespace std;
void main(void){
string str("");
char ch;
cout << "Type a string...\nstr=";
while((ch=getchar())!='\n') str+=ch;
cout << "The string is " << str << ".\n" << "The length = " << str.length() << ".\n";
}