Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7769 > unrolled thread
| Started by | eric <cneric12lin0@gmail.com> |
|---|---|
| First post | 2011-07-12 22:27 -0700 |
| Last post | 2011-07-13 00:56 -0700 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.c++
input/output trouble cause segmentation fault eric <cneric12lin0@gmail.com> - 2011-07-12 22:27 -0700
Re: input/output trouble cause segmentation fault Ian Collins <ian-news@hotmail.com> - 2011-07-13 18:02 +1200
Re: input/output trouble cause segmentation fault eric <cneric12lin0@gmail.com> - 2011-07-12 23:23 -0700
Re: input/output trouble cause segmentation fault eric <cneric12lin0@gmail.com> - 2011-07-13 00:56 -0700
| From | eric <cneric12lin0@gmail.com> |
|---|---|
| Date | 2011-07-12 22:27 -0700 |
| Subject | input/output trouble cause segmentation fault |
| Message-ID | <ebfce12c-127a-42f1-bd4b-ec42f2172ff7@v11g2000prn.googlegroups.com> |
Dear advanced c/g++ programers:
A program request me to enter twice input
that program probably is tested good on visual c++ 7.1 on window xp,
but my system is g++ on linux(Ubuntu10.04)
It assume
Enter some strings: a b c d
^Z
Enter some more strings: d e f g
^Z
Union: a b c d e f g
Difference: a b c
Intersection: d
all these you can get from page 273 and 274 of book(c++ cookbook)
but my test result is
-------------------------------
eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
Enter a series of strings: a b c d
^Z
[7]+ Stopped ./a.out
eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
Enter a series of strings: a b c d
{a, b, c, d}
Segmentation fault
-------------------------------------------------------------------
second case , I used <Enter><Control-D>
first case, I used <Enter><Control-Z>
the following in the program I tested, you still can download from
http://examples.oreilly.com/9780596007614/
------------------------------------------------------------------------------------------------
// Example 7-8. Unsing set operations
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <iterator>
#include "utils.h" // For parintContainer(): see 7.10
using namespace std;
int main() {
cout << "Enter some strings: "
istream_iterator<string> start(cin);
istream_iterator<string> end;
set<string> s1(start, end);
cin.clear();
cout << "Enter some more strings: ";
set<string> s2(++start, end);
set<string> setUnion;
set<string> setInter;
set<string> setDiff;
set_union(s1.begin(), s1.end(),
s2,begin(), s2.end(),
inserter(setUnion, setUnion.begin()));
set_difference(s1.begin(), s1.end(),
s2.begin(), s2.end(),
inserter(setDiff, setDiff.begin()));
cout << "Union:\n";
printContainer(setUnion);
cout << "Difference:\n";
printContainer(setDiff);
cout << "Intersection:\n";
printContainer(setinter);
}
--------------------------------------------------------------------------------------------------
utils.h
-------------------------------
// Example 7-12. Writing your own printing function
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
template<typename C>
void printContainer(const C& c, char delim = ',', ostream& out = cout)
{
printRange(c.begin(), c.end(), delim, out);
}
template<typename Fwd>
void printRange(Fwd first, Fwd last, char delim = ',', ostream& out =
cout) {
out << "{";
while (first != last) {
out << *first;
if (++first != last)
out << delim << ' ';
}
out << "}" << endl;
}
------------------------------------------------------------------------------------------------------------------
Ned and thanks your help a lot in advance
Eric
[toc] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-07-13 18:02 +1200 |
| Message-ID | <984qq7FglrU3@mid.individual.net> |
| In reply to | #7769 |
On 07/13/11 05:27 PM, eric wrote:
> Dear advanced c/g++ programers:
>
> A program request me to enter twice input
> that program probably is tested good on visual c++ 7.1 on window xp,
> but my system is g++ on linux(Ubuntu10.04)
> It assume
> Enter some strings: a b c d
> ^Z
> Enter some more strings: d e f g
> ^Z
> Union: a b c d e f g
> Difference: a b c
> Intersection: d
> all these you can get from page 273 and 274 of book(c++ cookbook)
>
> but my test result is
> -------------------------------
> eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
> Enter a series of strings: a b c d
> ^Z
> [7]+ Stopped ./a.out
> eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
> Enter a series of strings: a b c d
> {a, b, c, d}
> Segmentation fault
What does your debugger tell you?
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | eric <cneric12lin0@gmail.com> |
|---|---|
| Date | 2011-07-12 23:23 -0700 |
| Message-ID | <f9149245-d244-4348-a2fb-3eda80614624@f39g2000prb.googlegroups.com> |
| In reply to | #7770 |
On Jul 12, 11:02 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> On 07/13/11 05:27 PM, eric wrote:
>
>
>
> > Dear advanced c/g++ programers:
>
> > A program request me to enter twice input
> > that program probably is tested good on visual c++ 7.1 on window xp,
> > but my system is g++ on linux(Ubuntu10.04)
> > It assume
> > Enter some strings: a b c d
> > ^Z
> > Enter some more strings: d e f g
> > ^Z
> > Union: a b c d e f g
> > Difference: a b c
> > Intersection: d
> > all these you can get from page 273 and 274 of book(c++ cookbook)
>
> > but my test result is
> > -------------------------------
> > eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
> > Enter a series of strings: a b c d
> > ^Z
> > [7]+ Stopped ./a.out
> > eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
> > Enter a series of strings: a b c d
> > {a, b, c, d}
> > Segmentation fault
>
> What does your debugger tell you?
>
> --
> Ian Collins
Thanks your reply
I modify some
it have output, but its output not exactly match book predict,
especially, when I input
a b c d
then
d e f g
Union: is match
difference is match
but
Intersection is not
My result is {}, but book expect d
and I think book is correct
so plz help again, thanks a lot in advance
Eric
[toc] | [prev] | [next] | [standalone]
| From | eric <cneric12lin0@gmail.com> |
|---|---|
| Date | 2011-07-13 00:56 -0700 |
| Message-ID | <74ede8d2-1a23-4e69-aa5b-ad30525228f0@28g2000pry.googlegroups.com> |
| In reply to | #7771 |
On Jul 12, 11:23 pm, eric <cneric12l...@gmail.com> wrote:
> On Jul 12, 11:02 pm, Ian Collins <ian-n...@hotmail.com> wrote:
>
>
>
> > On 07/13/11 05:27 PM, eric wrote:
>
> > > Dear advanced c/g++ programers:
>
> > > A program request me to enter twice input
> > > that program probably is tested good on visual c++ 7.1 on window xp,
> > > but my system is g++ on linux(Ubuntu10.04)
> > > It assume
> > > Enter some strings: a b c d
> > > ^Z
> > > Enter some more strings: d e f g
> > > ^Z
> > > Union: a b c d e f g
> > > Difference: a b c
> > > Intersection: d
> > > all these you can get from page 273 and 274 of book(c++ cookbook)
>
> > > but my test result is
> > > -------------------------------
> > > eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
> > > Enter a series of strings: a b c d
> > > ^Z
> > > [7]+ Stopped ./a.out
> > > eric@eric-laptop:~/cppcookbook/ch7$ ./a.out
> > > Enter a series of strings: a b c d
> > > {a, b, c, d}
> > > Segmentation fault
>
> > What does your debugger tell you?
>
> > --
> > Ian Collins
>
> Thanks your reply
> I modify some
> it have output, but its output not exactly match book predict,
> especially, when I input
> a b c d
> then
> d e f g
> Union: is match
> difference is match
> but
> Intersection is not
> My result is {}, but book expect d
> and I think book is correct
> so plz help again, thanks a lot in advance
> Eric
never mind
I miss a section
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web