input/output trouble cause segmentation fault
eric
fsshl at att.net
Fri Jul 22 01:04:51 UTC 2011
Dear Andreychuk and/or ubuntu developers:
thanks your reply and concern,
it solved
it caused by
my a.out is actually Example 7-7, but I thought it is 7-8, so I enter
7-8's input(suggested by book)
then it cause (bad result), /* but why,
in 7-7, the main line is
vector<string>::iterator p =
partition(v.begin(), v.end(),
bind2nd(less<string>(), "foo"));
why the input of 7-8 feed in to 7-7 (above) will
cause "Segmentation fault"?
is another interesting assignment
*/
now I have another question also on this same book,
on its Example 11-11. Generating random numbers using rand
I follow/copy that book's code
it can compile and run
but
I am curious since it is random number and it seed by clock()
srand(static_cast<unsigned int>(clock()));
why it always output same result?
then someone in linuxquestions.org told me, clock() is used as cpu
speed , so it is always same
he suggest I should change it as time()
but then I got compile erros as following
----g++ 4.5.2-----------------------------
eric at eric-laptop:~/cppcookbook/ch11$ g++ Example11-11.cpp
Example11-11.cpp: In function ‘int main()’:
Example11-11.cpp:14:41: error: too few arguments to function ‘time_t
time(time_t*)’
/usr/include/time.h:186:15: note: declared here
----------------
I am hard to find any useful resource about how to use time() as
seed to generate random number in web. /* or maybe I not industry
enough */ plz help
Eric
----------------------------------------------------------------
On Thu, 2011-07-21 at 22:49 +0400, Dmitry Andreychuk wrote:
> On Tue, 2011-07-12 at 22:48 -0700, 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 at eric-laptop:~/cppcookbook/ch7$ ./a.out
> > Enter a series of strings: a b c d
> > ^Z
> > [7]+ Stopped ./a.out
> > eric at 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>
>
> Sorry for a late answer.
> I've just run it and had no segfault (using <Enter><Control-D>).
> Ubuntu 11.04; g++ 4.5.2-1ubuntu3
> Try debugging it with gdb.
>
>
> --
> Dmitry Andreychuk
>
>
More information about the Ubuntu-devel-discuss
mailing list