Sample Qustion 2
Write a C++ program to read a string input from the user and removes all characters except alphabets (remove all numbers, special characters)
#include<iostream>
#include<string>
using namespace std;
int main()
{
string line;
cout << "Enter a string: " << endl;
getline(cin, line);
for(int i = 0; i < line.size(); ++i)
{
if (!((line[i] >= 'a' && line[i]<='z') || (line[i] >= 'A' && line[i]<='Z')))
{
line[i] = '\0';
}
}
cout << "Output String: " << line;
return 0;
}
download file cpp file
do you have any qustion please comment
click the advertisement to help for me ....
#include<iostream>
#include<string>
using namespace std;
int main()
{
string line;
cout << "Enter a string: " << endl;
getline(cin, line);
for(int i = 0; i < line.size(); ++i)
{
if (!((line[i] >= 'a' && line[i]<='z') || (line[i] >= 'A' && line[i]<='Z')))
{
line[i] = '\0';
}
}
cout << "Output String: " << line;
return 0;
}
download file cpp file
do you have any qustion please comment
click the advertisement to help for me ....
Ammo eka
ReplyDelete