473,739 Members | 5,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't remove punctuation from string (compile error)

I'm trying to remove punctuation from a string with the following
code:

----------------------------
#include <string>
#include <algorithm>
#include <cctype>
..
using namespace std
..
..
..
string temp = "blah?yo!";
temp.erase(remo ve_if(temp.begi n(), temp.end(), ispunct), temp.end());
----------------------------

But I keep getting the following compilation error:

"error: no matching function for call to
`remove_if(__gn u_cxx::__normal _iterator<char* , std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char >,
__gnu_cxx::__no rmal_iterator<c har*, std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char >, <unknown type>)'"

Any idea what's wrong?

--
Tashfeen Bhimdi
Oct 11 '06 #1
6 3704
* Tashfeen Bhimdi:
I'm trying to remove punctuation from a string with the following
code:

----------------------------
#include <string>
#include <algorithm>
#include <cctype>
.
using namespace std
.
.
.
string temp = "blah?yo!";
temp.erase(remo ve_if(temp.begi n(), temp.end(), ispunct), temp.end());
----------------------------

But I keep getting the following compilation error:

"error: no matching function for call to
`remove_if(__gn u_cxx::__normal _iterator<char* , std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char >,
__gnu_cxx::__no rmal_iterator<c har*, std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char >, <unknown type>)'"

Any idea what's wrong?
'unknown type' means the compiler doesn't know what that thing is.

Which means you've forgotten to include the relevant header (I'll leave
it to you to find out which header that is).

Also, there's a missing semicolon; always copy and paste code, otherwise
the code presented may have other errors than your real code, and may
not exemplify the real code at all.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 11 '06 #2
Tashfeen Bhimdi wrote:
I'm trying to remove punctuation from a string with the following
code:

----------------------------
#include <string>
#include <algorithm>
#include <cctype>
.
using namespace std
.
.
.
string temp = "blah?yo!";
temp.erase(remo ve_if(temp.begi n(), temp.end(), ispunct), temp.end());
----------------------------

But I keep getting the following compilation error:

"error: no matching function for call to
`remove_if(__gn u_cxx::__normal _iterator<char* , std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char >,
__gnu_cxx::__no rmal_iterator<c har*, std::basic_stri ng<char,
std::char_trait s<char>, std::allocator< char >, <unknown type>)'"

Any idea what's wrong?
'ispunct' takes 'int' as its argument, not 'char'. Could that be
the cause?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 11 '06 #3
'unknown type' means the compiler doesn't know what that thing is.
>
Which means you've forgotten to include the relevant header (I'll leave
it to you to find out which header that is).

Also, there's a missing semicolon; always copy and paste code, otherwise
the code presented may have other errors than your real code, and may
not exemplify the real code at all.

I believe I have all the headers correct (string, algorithm for
remove_if, and cctype for ispunct). The missing semicolon was a typo on
my part.

I was just following what I read in this post:
http://groups.google.com/group/comp....c8495abc35fd6b

Seemed simple enough. Here is the function I'm using the code in,
copy&paste:

-----------------------------
#include <iostream>
#include <map>
#include <fstream>
#include <string>
#include <algorithm>
#include <cctype>

using namespace std;

..
..
..

map<string, intBuildDiction ary(string &textfile) {
map<string, intdict;
ifstream infile;
infile.open(tex tfile.c_str());
string word;

while (infile >word) {
word.erase(remo ve_if(word.begi n(), word.end(), ispunct), word.end());
dict[word]++;
}

infile.close();
return dict;
}
-----------------------------
--
Tashfeen Bhimdi
Oct 11 '06 #4
* Tashfeen Bhimdi:
>'unknown type' means the compiler doesn't know what that thing is.

Which means you've forgotten to include the relevant header (I'll
leave it to you to find out which header that is).

Also, there's a missing semicolon; always copy and paste code,
otherwise the code presented may have other errors than your real
code, and may not exemplify the real code at all.


I believe I have all the headers correct (string, algorithm for
remove_if, and cctype for ispunct).
Yes, on reflection, you do. Sorry that I leapt to an unwarranted
conclusion.

The missing semicolon was a typo on
my part.

I was just following what I read in this post:
http://groups.google.com/group/comp....c8495abc35fd6b
Seemed simple enough. Here is the function I'm using the code in,
copy&paste:

-----------------------------
#include <iostream>
#include <map>
#include <fstream>
#include <string>
#include <algorithm>
#include <cctype>

using namespace std;

.
.
.

map<string, intBuildDiction ary(string &textfile) {
Just a nit (but important in general): make that 'string const&'.

map<string, intdict;
ifstream infile;
infile.open(tex tfile.c_str());
string word;

while (infile >word) {
word.erase(remo ve_if(word.begi n(), word.end(), ispunct),
word.end());
dict[word]++;
}

infile.close();
return dict;
}
Try

static_cast<int (*)(int)>( ispunct )

to disambiguate which function 'ispunct' refers to.

The problem seems to be that one of the headers you do include in turn
includes a definition of the C++ library's own 'ispunct', from <locale>,
in addition to the C library's 'ispunct' from <cctype>.

Hth.,

- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 11 '06 #5
>map<string, intBuildDiction ary(string &textfile) {
>
Just a nit (but important in general): make that 'string const&'.
Done, thanks for the tip.
Try

static_cast<int (*)(int)>( ispunct )

to disambiguate which function 'ispunct' refers to.

The problem seems to be that one of the headers you do include in turn
includes a definition of the C++ library's own 'ispunct', from <locale>,
in addition to the C library's 'ispunct' from <cctype>.

Perfect, that line works!

So how did you know what the problem was? I couldn't figure out from
the error and Eclipse was no help at all either (what I'm currently
using to code).

And another question, why does that static_cast<... .work to
disambiguate? Strange how it specifies which library to use.

Thanks again.

--
Tashfeen Bhimdi
Oct 11 '06 #6
* Tashfeen Bhimdi:
* Alf P. Steinbach:
>>
Try

static_cast<int (*)(int)>( ispunct )

to disambiguate which function 'ispunct' refers to.

The problem seems to be that one of the headers you do include in turn
includes a definition of the C++ library's own 'ispunct', from
<locale>, in addition to the C library's 'ispunct' from <cctype>.


Perfect, that line works!

So how did you know what the problem was?
'unknown type' means the compiler doesn't know what that thing is. In
my first posting I (erronously) assumed that was because the relevant
header hadn't been included. Another likely possibility, which it seems
applied here, is that there is an ambigious reference to something.

And another question, why does that static_cast<... .work to
disambiguate? Strange how it specifies which library to use.
It doesn't specify the library: it specifies the function signature,
i.e. which function overload.

As an alternative you could define your own wrapper function, e.g.

bool isPunctuation( char ch ) { return !!ispunct( ch ); }

and use that directly without any disambiguation device, since now there
would be no ambiguity.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 11 '06 #7

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

Similar topics

3
5783
by: Venkat | last post by:
Hi All, Currently i guess rename and remove are not supported using fstream. How do i rename or remove a file? regards, Venkat
7
5727
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning is to improve, but not to prove.
19
9590
by: ashmangat | last post by:
Hi! now on the chapter "string-class" My assignment is below Word Counter: Write a function that accepts a pointer to a C-String as an argument and returns the number of words contained in the string. For instance, if the string argument is "Four score and seven years ago" the function should return the number 6. Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The number of...
1
1664
by: silverburgh.meryl | last post by:
Hi, I have this piece of code which calls STL remove(): _aList.erase(remove(_aList.begin(), _aList.end(), bd), _aList.end()); where _aList is a 'vector<A*>' and bd is 'A*' But i get this compile error:
8
1605
by: David Lee | last post by:
Hi, all I got the following code from http://builder.com.com/5100-6370_14-5079969.html, but it can't compile, neither can I figure out how to fix it. Anyone pls give me an explanation? 1 #include <string> 2 #include <sstream> 3 #include <iostream>
6
4896
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
1
1506
by: nickyeng | last post by:
I have done the following code, i just couldn't figure out why it can erase the punctuation in the end of each word(strr variable) ? i got this when i run it: http://i19.photobucket.com/albums/b171/NickyEng/program.jpg here is my function code: void testFunction(string str) { map<string, int> freq;
4
2773
by: khomsley | last post by:
Is there a way to make access ignore punctuation at the beginning of an item, such as "Field and Stream" so that it will arrange all information alphabetically instead of arranging items in quotes alphabetically, and then arranging items not in quotes alphabetically? Thanks
4
1915
by: kdsutaia | last post by:
hi! i m trying to do something like this. as I am doing tockenization. and wants to include all punctuation mark as tocken. if($punctuation){ grep {$p =~ m/$_/' '.$_.' '/g)} ("\.", "\%", "\'", "\\", "\", "\{", "\}", "\"", "\>", "\?", "\<", "\#", "\~", "\=", "\&", "\*", "\,", "\!", "\@", "\$", "\(", "\)", "\+", "\-", "\_", "\|", "\:", "\;", "\.", "\/", "\$", "\@", "\-", "\'", "\``"); }
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.