473,396 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getline and substr

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

if (postco[0]!=0 && isdigit(postco[0] ))
{
cout <<"s ";
cin.get();
}
else
{
cout<< "w";
cin.get();
}

if (postco.substr(4,2)!=" ") //24 request for member `substr'
in
{
cout<<"G";
cin.get();
}
else
{
cout<<"ng";
cin.get();
}
}
Jul 22 '05 #1
4 2647
Hi,
"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote in message
news:bs**********@news.cistron.nl...
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()
{
string postco;
i.s.o char postco
char postco[7];
cout<<"postcode : ";
getline(postco,7); //11 no matching function for
call

if (postco[0]!=0 && isdigit(postco[0] ))
{
cout <<"s ";
cin.get();
}
else
{
cout<< "w";
cin.get();
}

if (postco.substr(4,2)!=" ") //24 request for member `substr' in
{
cout<<"G";
cin.get();
}
else
{
cout<<"ng";
cin.get();
}
}


Regards, Ron AF Greve.
Jul 22 '05 #2
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;
}

Jul 22 '05 #3

"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote in message
news:bs**********@news.cistron.nl...
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?

postco is an array of 7 char, it is NOT a string,
Change the definition to
string postco;

Jul 22 '05 #4
Thank you very much, three of you.
I 'd take a try, it works.
Regards

Wen

"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> schreef in
bericht news:bs**********@news.cistron.nl...
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

if (postco[0]!=0 && isdigit(postco[0] ))
{
cout <<"s ";
cin.get();
}
else
{
cout<< "w";
cin.get();
}

if (postco.substr(4,2)!=" ") //24 request for member `substr' in
{
cout<<"G";
cin.get();
}
else
{
cout<<"ng";
cin.get();
}
}

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: MuffinMan | last post by:
Hi, I'm trying to add up an integer with the result from substr() like $second_int = substr( .... ) + $int; I know the result from substr() is an integer and so is $int but in the end...
2
by: Michael Easterly | last post by:
What is a good way to read a text file and read each line, then assign data to variables? I have this so far, #include <iostream> #include <fstream> using namespace std; string...
1
by: ma740988 | last post by:
Consider: ifstrem MyFile("extractMe.txt"); string Str; getline(MyFile, Str); getline above extracts the contents of MyFile and place into the string object. Deduced using FROM/TO logic I...
10
by: Skywise | last post by:
I keep getting the following error upon compiling: c:\c++ files\programs\stellardebug\unitcode.h(677) : error C2664: 'class istream &__thiscall istream::getline(char *,int,char)' : cannot convert...
18
by: Amadeus W. M. | last post by:
I'm trying to read a whole file as a single string, using the getline() function, as in the example below. I can't tell what I'm doing wrong. Tried g++ 3.2, 3.4 and 4.0. Thanks! #include...
2
by: lawpoop | last post by:
Hey folks - I'm working on a spellchecking routine. The pspell libraries don't handle punctuation; I have to make a script a little smarter. I'm having a problem popping English posessive...
6
by: JML | last post by:
Hi, I have some code which parses a text file and creates objects based on what is in the text file. The code works just fine on Windows, but when I compile it using XCode on OS X the parsing...
11
by: rory | last post by:
I am reading a binary file and I want to search it for a string. The only problem is that failbit gets set after only a few calls to getline() so it never reaches the end of the file where the...
5
by: erictheone | last post by:
so here is my code. My getlines for the strings keyword and phrase at lines 44 and 79 respectively don't work. Please help!!! #include <cstdlib> #include <string> #include <iostream> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.