Kees Hoogendijk wrote:
Hallo,
I've got 2 error msg, line 11 and 24. I don't understand both of them.
Can someone type me in the normal language and help me here out?
TI@
Wen
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
char postco[7];
cout<<"postcode : ";
getline(postco,7); //11 no matching function for call
cin.getline( postco, 7 ); // ITYM
if (postco[0]!=0 && isdigit(postco[0] ))
{
cout <<"s ";
cin.get();
}
else
{
cout<< "w";
cin.get();
}
cout << ( isdigit( postco[ 0 ] ) ? "s " : "w" );
cin.get( );
if (postco.substr(4,2)!=" ") //24 request for member `substr' in
If you want substr, use a std::string instead of an array of characters.
Anyway, the two strings used here will never be the same. The one on
the left has length two, but the one on the right has length 1.
{
cout<<"G";
cin.get();
}
else
{
cout<<"ng";
cin.get();
}
}
What's with all those cin.get()'s? Here's how to do what I think you meant.
#include <iostream>
#include <string>
#include <cctype>
/* Format a postal code.
*/
std::string format( std::string const& s )
{
if( s.empty( ) )
{
throw "Can't format postal code for empty string.";
}
return
std::string( "postcode: " ) +
( std::isdigit( s[ 0 ] ) ? "s " : "w" ) +
( s.substr( 4, 1 ) != " " ? "G" : "ng" );
}
int main( )
{
std::string postal_code;
std::getline( std::cin, postal_code );
std::cout << format( postal_code ) << std::endl;
}