473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using 'random_sample'...

I'm just a tad frustrated right now, because I need to ask such a n00b
question. I'm trying to use 'random_sample', however, I'm getting back a
compiler error saying; " `random_sample' undeclared (first use this
function) ". I've looked a my C++ header file 'algorithm', and its
definition seems to be there. When I include the old style, algo.h, I only
get a warning, but compilation is successful. Should I just use algo.h,
because the SGI STL documentation says it should exist in header
'algorithm'. What am I doing wrong?!

d
Jul 23 '05 #1
7 1721
deancoo wrote:
What am I doing wrong?!


Misspelling random_shuffle?

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #2
deancoo wrote:
I'm just a tad frustrated right now, because I need to ask such a n00b
question. I'm trying to use 'random_sample', however, I'm getting back a
compiler error saying; " `random_sample' undeclared (first use this
function) ". I've looked a my C++ header file 'algorithm', and its
definition seems to be there. When I include the old style, algo.h, I only
get a warning, but compilation is successful. Should I just use algo.h,
because the SGI STL documentation says it should exist in header
'algorithm'. What am I doing wrong?!

d

`random_sample' is an SGI extension, not part of the standard C++
library -- but using `std::random_sample' is likely to work.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #3

"Artie Gold" <ar*******@austin.rr.com> wrote in message
news:39*************@individual.net...
deancoo wrote:
I'm just a tad frustrated right now, because I need to ask such a n00b
question. I'm trying to use 'random_sample', however, I'm getting back a
compiler error saying; " `random_sample' undeclared (first use this
function) ". I've looked a my C++ header file 'algorithm', and its
definition seems to be there. When I include the old style, algo.h, I
only get a warning, but compilation is successful. Should I just use
algo.h, because the SGI STL documentation says it should exist in header
'algorithm'. What am I doing wrong?!

d

`random_sample' is an SGI extension, not part of the standard C++
library -- but using `std::random_sample' is likely to work.

Hmmm, still not working.
Jul 23 '05 #4
What compiler are you using. Early version of gcc3.. had non standard
STL headers in a separate directory under the __gnu_cxx namespace. Is
that the case with you?

Jul 23 '05 #5
3.4.2
"Raghu Uppalli" <ra****@rocketmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
What compiler are you using. Early version of gcc3.. had non standard
STL headers in a separate directory under the __gnu_cxx namespace. Is
that the case with you?

Jul 23 '05 #6
My earlier comment may be misleading. Newer versions of gcc/g++ also
have non-standard includes in ext/.

I am assuming you mean gcc-3.4.2. The following works for me...on gcc
3.4.2

#include <ext/algorithm>
#include <iostream>
#include <vector>
using namespace std;
using namespace __gnu_cxx;

int main()
{
const int a = 5;
const int b = 2;
int A[] = {1, 2, 3, 4, 5};
int B[b];
for ( int cnt = 0; cnt < 10; ++cnt) {
random_sample(A, A+a, B, B+b);
cout << "Turn " << cnt << ": " ;
for (int i =0; i < b; ++i) {
cout << B[i] << " ";
}
cout << endl;
}
}

Jul 23 '05 #7
"Raghu Uppalli" <ra****@rocketmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
My earlier comment may be misleading. Newer versions of gcc/g++ also
have non-standard includes in ext/.

I am assuming you mean gcc-3.4.2. The following works for me...on gcc
3.4.2

#include <ext/algorithm>
#include <iostream>
#include <vector>
using namespace std;
using namespace __gnu_cxx;

int main()
{
const int a = 5;
const int b = 2;
int A[] = {1, 2, 3, 4, 5};
int B[b];
for ( int cnt = 0; cnt < 10; ++cnt) {
random_sample(A, A+a, B, B+b);
cout << "Turn " << cnt << ": " ;
for (int i =0; i < b; ++i) {
cout << B[i] << " ";
}
cout << endl;
}
}


Yup, that was the problem. I wasn't giving the extra bit of path
information in the include statement for the compiler to find the
non-standard algorithm header file.

Thanks a lot dude! Now I don't have to get that darn warning each time I
compile.

Cheers,
d
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
10
by: Christopher Benson-Manica | last post by:
Why can't I use a class destructor in a using declaration: using MyClass::~MyClass; ? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org ...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.