int main (int argc, char * const argv[]) {
Punct_stream ps(cin);
ps.whitespace(";:,.?!()\"{}<>");
ps.case_sensitive(false);
cout << "Please enter words\n";
vector<string> vs;
string word;
while (ps >> word)
vs.push_back(word); // read words
for (int i=0; i<vs.size(); ++i) {
if (i==0 || vs[i] != vs[i-1])cout << vs[i]<<endl;
}
return 0;
}
It keeps looping in the
> while (ps >> word)
> vs.push_back(word); // read words
and never executes the code that follows the loop.
I have done some debugging and the
> operator bool ()
is always returning true.
I have tried with the original code downloaded from the net.
I'm trying this in a mac with xcode. Maybe this is a problem related with my compiler. Anyone with this problem?
Regards,
David
On Jan 30, 2011, at 4:39 PM, David Jorge wrote:
> Hi guys,
> There is a problem with this exercise.
>
> int main (int argc, char * const argv[]) {
> Punct_stream ps(cin);
> ps.whitespace(";:,.?!()\"{}<>");
> ps.case_sensitive(false);
>
> cout << "Please enter words\n";
> vector<string> vs;
> string word;
>
> while (ps >> word)
> vs.push_back(word); // read words
>
> for (int i=0; i<vs.size(); ++i) {
> if (i==0 || vs[i] != vs[i-1])cout << vs[i]<<endl;
> }
>
> return 0;
> }
>
> It keeps looping in the
>
>> while (ps >> word)
>> vs.push_back(word); // read words
>
>
> and never executes the code that follows the loop.
How are you terminating the input?
Art Werschulz (8-{)} "Metaphors be with you." -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y?
Internet: agw STRUDEL comcast.net
> --
> You received this message because you are subscribed to the Google Groups "PPP-public" group.
> To post to this group, send email to ppp-p...@googlegroups.com.
> To unsubscribe from this group, send email to ppp-public+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ppp-public?hl=en.
>
On Jan 30, 2011, at 6:48 PM, David Jorge wrote:
> I'm not terminating the input, and it is not mentioned in the book but your question makes sense. Should i use a word like "END"? or "\r\n"?
In Unix, end-of-input from the terminal is generated by control-D.
In Windows, it's control-Z.