Re: input/output trouble cause segmentation fault

2011-07-25 Thread Dmitry Andreychuk
On Fri, Jul 22, 2011 at 5:04 AM, eric  wrote:

>
> 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
>
>
$ man 2 time

srand( static_cast( time(0) ) );

--
Dmitry Andreychuk
-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss


Re: input/output trouble cause segmentation fault

2011-07-21 Thread eric
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::iterator p =
partition(v.begin(), v.end(),
bind2nd(less(), "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(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@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@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 
> > first case, I used 
> 
> Sorry for a late answer.
> I've just run it and had no segfault (using ).
> Ubuntu 11.04; g++ 4.5.2-1ubuntu3
> Try debugging it with gdb.
> 
> 
> -- 
> Dmitry Andreychuk
> 
> 



-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss


Re: input/output trouble cause segmentation fault

2011-07-21 Thread Dmitry Andreychuk
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@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 
> first case, I used 

Sorry for a late answer.
I've just run it and had no segfault (using ).
Ubuntu 11.04; g++ 4.5.2-1ubuntu3
Try debugging it with gdb.


-- 
Dmitry Andreychuk


-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss


Re: input/output trouble cause segmentation fault

2011-07-12 Thread eric
thanks your quick reply
but that's I tried
result is segmentation fault
which is not what book predict(or what program will follow)
as you can see, it should response another cout
"Enter some more strings: ";
but it never reach there.
that's what I need you(or any advanced c/g++/linux/ubuntu programers'
help.

On Wed, 2011-07-13 at 13:50 +0800, Ace wrote:
> Unlike Windows, GNU/Linux use ^D instead of ^Z .
> 
> On 13 July 2011 13:48, 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
> ---
> second case , I used 
> first case, I used 
> 
> the following is the program I tested, you still can download
> from
> http://examples.oreilly.com/9780596007614/
> 
> 
> // Example 7-8.  Unsing set operations
> #include 
> #include 
> #include 
> #include 
> #include 
> #include "utils.h"  // For parintContainer(): see 7.10
> 
> using namespace std;
> 
> int main() {
> 
>  cout << "Enter some strings: "
>  istream_iterator start(cin);
>  istream_iterator end;
>  set s1(start, end);
> 
>  cin.clear();
> 
>  cout << "Enter some more strings: ";
>  set s2(++start, end);
> 
>  set setUnion;
>  set setInter;
>  set 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 
> #include 
> #include 
> #include 
> #include 
> 
> using namespace std;
> 
> template
> void printContainer(const C& c, char delim = ',', ostream& out
> = cout)
> {
>   printRange(c.begin(), c.end(), delim, out);
> }
> 
> template
> 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
> 
> 
> 
> --
> Ubuntu-devel-discuss mailing list
> Ubuntu-devel-discuss@lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss
> 
> 
> 
> -- 
> 
> DaoKuan Ma (Ace)
> Software Group of CIPPUS-Center of Innovation & Practice.
>   
> 
> ADD: Software School of Dalian University of Technology.
> TEL:  +86-186-0984-1079.
> 
> BLOG:http://t.matong.me
> EMAIL:  madaok...@gmail.com  go...@acm.org
> --
> CONTACT ME: 
> 



-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-deve

input/output trouble cause segmentation fault

2011-07-12 Thread eric
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 
first case, I used 

the following is the program I tested, you still can download from
http://examples.oreilly.com/9780596007614/

// Example 7-8.  Unsing set operations
#include 
#include 
#include 
#include 
#include 
#include "utils.h"  // For parintContainer(): see 7.10

using namespace std;

int main() {

  cout << "Enter some strings: "
  istream_iterator start(cin);
  istream_iterator end;
  set s1(start, end);

  cin.clear();

  cout << "Enter some more strings: ";
  set s2(++start, end);

  set setUnion;
  set setInter;
  set 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 
#include 
#include 
#include 
#include 

using namespace std;

template
void printContainer(const C& c, char delim = ',', ostream& out = cout)
{
   printRange(c.begin(), c.end(), delim, out);
}

template
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



-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss