Home | Community | Message Board

Kratom Eye
This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

PhytoExtractum Shop: Maeng Da Thai Kratom Leaf Powder

Jump to first unread post Pages: 1
OfflineGainer
Syzurp
 User Gallery


Registered: 10/20/04
Posts: 1,468
Loc: Ðirty §outh
Last seen: 8 days, 14 minutes
Anyone really good at C++ and using STL I need some help
    #7991939 - 02/07/08 02:24 PM (15 years, 11 months ago)

Code:

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <iterator>
#include <algorithm>

using namespace std;

int counter = 0;
void count(string &s);

int main(int argc, char *argv[]){

string from, to;

cin >> from;
ifstream is(from.c_str());
istream_iterator<string> ii(is);
istream_iterator<string> eos;

vector<string> b(ii, eos);
sort(b.begin(), b.end());
ofstream os(to.c_str());

for_each(b.begin(), b.end(), count);

return 0;
}

void count(string &s){

for(int i = 0; i < s.length();i++){
if(s[i] == 'e' || s[i] == 'E'){
counter++;
}
}
}




This line is giving me problems.
for_each(b.begin(), b.end(), count);

It should step through the vector and pass each string to the count function but the compiler always spits up this crap:

eCount.cpp: In function âint main(int, char**)â:
eCount.cpp:32: error: no matching function for call to âfor_each(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, <unresolved overloaded function type>)â


Any help would be much appreciated.


--------------------
"I mean, it's like a koala bear crapped a rainbow in my brain!"
-Captain Murphy

"Quit being a bitch and pill me up"
-Dr. Quinn

"Smoke that bitch"
"I am not Stormy, I am He who smokes Bitches!"
-Stormy


Extras: Filter Print Post Top
OfflineGainer
Syzurp
 User Gallery


Registered: 10/20/04
Posts: 1,468
Loc: Ðirty §outh
Last seen: 8 days, 14 minutes
Re: Anyone really good at C++ and using STL I need some help [Re: Gainer]
    #7994362 - 02/07/08 11:04 PM (15 years, 11 months ago)

Bump anyone?... Or anyone know of a good C++ forum.. No I'm not that lazy googling it now just wondering if anyone has any suggestions.


--------------------
"I mean, it's like a koala bear crapped a rainbow in my brain!"
-Captain Murphy

"Quit being a bitch and pill me up"
-Dr. Quinn

"Smoke that bitch"
"I am not Stormy, I am He who smokes Bitches!"
-Stormy


Extras: Filter Print Post Top
InvisibleBoom
just a tester
Male
Registered: 06/16/04
Posts: 11,252
Loc: Cypress Creek
Re: Anyone really good at C++ and using STL I need some help [Re: Gainer]
    #7994437 - 02/07/08 11:32 PM (15 years, 11 months ago)

shouldn't you be sending an ostream to the function "count"?


something like:

for_each(b.begin(), b.end(), count(os));


Extras: Filter Print Post Top
InvisibleBoom
just a tester
Male
Registered: 06/16/04
Posts: 11,252
Loc: Cypress Creek
Re: Anyone really good at C++ and using STL I need some help [Re: Boom]
    #7994443 - 02/07/08 11:34 PM (15 years, 11 months ago)

wait nevermind

I'll think about it


Extras: Filter Print Post Top
InvisibleBoom
just a tester
Male
Registered: 06/16/04
Posts: 11,252
Loc: Cypress Creek
Re: Anyone really good at C++ and using STL I need some help [Re: Boom]
    #7994459 - 02/07/08 11:39 PM (15 years, 11 months ago)

For one thing though, I'd get rid of the & in the functions...you don't need to be passing it in like that, do you?


Extras: Filter Print Post Top
OfflineGainer
Syzurp
 User Gallery


Registered: 10/20/04
Posts: 1,468
Loc: Ðirty §outh
Last seen: 8 days, 14 minutes
Re: Anyone really good at C++ and using STL I need some help [Re: Boom]
    #7994467 - 02/07/08 11:42 PM (15 years, 11 months ago)

I've tried it without gives same error message. I was just passing by reference cause thats what our teacher was doing in all his examples.


--------------------
"I mean, it's like a koala bear crapped a rainbow in my brain!"
-Captain Murphy

"Quit being a bitch and pill me up"
-Dr. Quinn

"Smoke that bitch"
"I am not Stormy, I am He who smokes Bitches!"
-Stormy


Extras: Filter Print Post Top
InvisibleBoom
just a tester
Male
Registered: 06/16/04
Posts: 11,252
Loc: Cypress Creek
Re: Anyone really good at C++ and using STL I need some help [Re: Gainer]
    #7994474 - 02/07/08 11:44 PM (15 years, 11 months ago)

you have to use the for_each function? That's some ugly syntax


Extras: Filter Print Post Top
OfflineGainer
Syzurp
 User Gallery


Registered: 10/20/04
Posts: 1,468
Loc: Ðirty §outh
Last seen: 8 days, 14 minutes
Re: Anyone really good at C++ and using STL I need some help [Re: Boom]
    #7994536 - 02/08/08 12:10 AM (15 years, 11 months ago)

Yeah I think so he's trying to get us good at using the STL and iterators. I could just write a loop to do it much easier.. I'm not sure though I think he only specified that we had to read in the file using iterators might be able to get away with just writing a loop.


--------------------
"I mean, it's like a koala bear crapped a rainbow in my brain!"
-Captain Murphy

"Quit being a bitch and pill me up"
-Dr. Quinn

"Smoke that bitch"
"I am not Stormy, I am He who smokes Bitches!"
-Stormy


Extras: Filter Print Post Top
OfflineGainer
Syzurp
 User Gallery


Registered: 10/20/04
Posts: 1,468
Loc: Ðirty §outh
Last seen: 8 days, 14 minutes
Re: Anyone really good at C++ and using STL I need some help [Re: Gainer]
    #7994586 - 02/08/08 12:25 AM (15 years, 11 months ago)

Code:

//CSC 317
//eCount.cpp

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <iterator>
#include <algorithm>

using namespace std;

int counter = 0;
void count(string &s);

int main(int argc, char *argv[]){

string from, to;
int main(int argc, char *argv[]){

string from, to;

cin >> from;
ifstream is(from.c_str());
istream_iterator<string> ii(is);
istream_iterator<string> eos;

vector<string> b(ii, eos);
sort(b.begin(), b.end());
ofstream os(to.c_str());

//for_each(b.begin(), b.end(), count);

for(vector<string>::iterator s = b.begin(); s != b.end();++s){
count(*s);
}

cout << "There are: " << counter << " e's." << endl;

return 0;
}

void count(string &s){

for(int i = 0; i < s.length();i++){
if(s[i] == 'e' || s[i] == 'E'){
counter++;
}
}
}




This code works fine yeah.. its some kinda ugly code right now got those global variables floating around in there fix that later. But anyway still can't figure out why the for_each() version doesn't work it shouldn't have any problems.


--------------------
"I mean, it's like a koala bear crapped a rainbow in my brain!"
-Captain Murphy

"Quit being a bitch and pill me up"
-Dr. Quinn

"Smoke that bitch"
"I am not Stormy, I am He who smokes Bitches!"
-Stormy


Extras: Filter Print Post Top
Jump to top Pages: 1

PhytoExtractum Shop: Maeng Da Thai Kratom Leaf Powder


Similar ThreadsPosterViewsRepliesLast post
* 6 string Bass
( 1 2 3 all )
Ripple 6,178 50 11/30/05 07:42 PM
by CaRnAgECaNdY
* An experiment w/guitar strings lid 1,984 13 11/15/05 11:58 PM
by adamj
* Jethro Tull appreciation thread! *update*(torrent included!)
( 1 2 all )
Lightningfractal 4,398 27 01/22/05 03:41 PM
by Phred
* Elixir strings
( 1 2 all )
FunkyLoFi 3,462 32 01/28/07 07:31 PM
by bluedolphin
* string theory danlennon3 815 10 10/20/05 10:35 PM
by DieCommie
* Strings... Cepheus 482 9 02/24/07 10:40 PM
by FunkyLoFi
* The other string theory (not quantum related) SneezingPenis 806 5 03/12/05 05:12 AM
by Twister
* Songs that are about, or include Psychedelics... from wiki. RoosterCogburn 1,446 1 05/04/07 08:50 AM
by OneMoreRobot3021

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: Entire Staff
503 topic views. 1 members, 38 guests and 41 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2024 Mind Media. Some rights reserved.

Generated in 0.023 seconds spending 0.008 seconds on 14 queries.