Hey, I was just making a program that, when a string of numbers and letters was entered, it would strip away any numbers and output all the letters. heres my code:
int main(int argc, char *argv[])
{
string input;
string a = input[0];
string b = input[1];
string c = input[2];
string d = input[3];
string e = input[4];
string f = input[5];
string g = input[6];
string h = input[7];
cout<< "This program will take a string of up to 8\n characters, and strip the numbers from it";
cout<< "\nEnter string: ";
cin>> input;
if (a.find_first_of ("1234567890") ==string::npos){
cout<< a ;
}
else if (a.find_first_of ("1234567890") != string::npos){
}
if (b.find_first_of ("1234567890") ==string::npos){
cout<< b;
}
else if (b.find_first_of ("1234567890") != string::npos){
}
if (c.find_first_of ("1234567890") ==string::npos){
cout<< c ;
}
else if (c.find_first_of ("1234567890") != string::npos){
}
if (d.find_first_of ("1234567890") ==string::npos){
cout<< d ;
}
else if (d.find_first_of ("1234567890") != string::npos){
}
if (e.find_first_of ("1234567890") ==string::npos){
cout<< e ;
}
else if (e.find_first_of ("1234567890") != string::npos){
}
if (f.find_first_of ("1234567890") == string::npos){
cout<< f ;
}
else if (f.find_first_of ("1234567890") != string::npos){
}
if (g.find_first_of ("1234567890") ==string::npos){
cout<< g ;
}
else if (g.find_first_of ("1234567890") != string::npos){
}
if (h.find_first_of ("1234567890") ==string::npos){
cout<< h ;
}
else if (h.find_first_of ("1234567890") != string::npos){
}
system("PAUSE");
return 0;
}
It says there is a conversion error for 'char' to 'const char'
Thanks
#include <cctype> // isdigit()
#include <iostream>
#include <limits> // numeric_limits
#include <string>
usingnamespace std;
int main()
{
// This is where we will put the user's string
string input;
// This is where we will put the modified string (user's string without numbers)
string output;
// Ask the user for the string
cout << "This program will take a string (of any length) and strip all the numbers from it.\n";
cout << "Enter the string: " << flush;
getline( cin, input );
// Now we can start removing stuff from the string...
// Use a loop to iterate through all the characters in input
// For each character that is not a digit (use the isdigit() function),
// append it to output
...
cout << "Press ENTER to quit." << flush;
cin.ignore( numeric_input <streamsize> ::max(), '\n' );
return 0;
}
or you can take the input in an array ... then running a loop can check that the particular word/ num isdigit....if yes then delete that particular num from array....
.
.
.In the end a set of string which is free of num will remain in an array ...
just cout the array ./.. and enjoy ... its not that much hard or lines of coding program....
thanks ,..