Wednesday, February 19, 2014

Iterator pair as a function argument?

Newsgroup: comp.lang.c++

Subject: Iterator pair as a function argument?

From: nvangogh <nvangogh@...>

Date: Wed, 19 Feb 2014 20:22:47 +0000



Suppose I have a vector<int> values. Now the pair values.begin() and

values.end() will cover the range of the vector.



I am writing a simple function that takes the pair of iterators as

arguments along with an int value. The function then returns a bool to

indicate if the int value is found in the vector.



The first problem I have is to question if it is possible to pass

iterators as distinct arguments to a function? I would have thought that

the only way to accomplish this would be to pass the vector as a

reference, from there the function can use the iterators to do it's work.



I was thinking the correct definition would be



bool find_value (vector<int>&, int);



Or is there a way to pass an iterator pair as function arguments which I

have missed?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1jJceFN

View all the progranning help forums at:

http://ift.tt/1dP9txN

could an braced-init-list be a first-class expression?

Newsgroup: comp.lang.c++

Subject: could an braced-init-list be a first-class expression?

From: pietro.cerutti@...

Date: Wed, 19 Feb 2014 10:47:33 -0800 (PST)



I'm wondering what would prevent an initialization list from being a first-class expression of type std::initializer_list.



I understand that the current standar allows braced-init-lists to appear only when assigning to a scalar of type T or to an object of a class taking an std::initializer_list in the assignment operator.



Having



void f (std::vector<double> v);



It is currently possible to do this:



auto a {1, 2, 3}:

g (a);



but not to do this:



g ({1, 2, 3});



As I see it, all information the compiler needs is there. Is there any specific reason why this isn't possible?



Thanks,







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6McR

View all the progranning help forums at:

http://ift.tt/1dP9txN

IO problem

Newsgroup: comp.lang.c++

Subject: IO problem

From: nvangogh <nvangogh@...>

Date: Wed, 19 Feb 2014 14:29:18 +0000



I have come to a question in C++ Primer (p 314 , exercise 8.1) that is

not clear to me.

"Write a function that takes and returns an istream&. The function

should read the stream until it hits end-of-file. The function should

print what it reads to the standard output. Reset the stream so that it

is valid before returning the stream."



Breaking this down, the function has to do three things:



1. Read a stream until it hits end-of-file

So the >> operator reads input from an istream object - cin.

This stream's end of file can be interrogated by

cin.eof(). This returns true if the end of file bit is set which can be

tested with a bool variable

bool on = false;

on = cin.eof();

if(on == true)

// end of file is reached, else

if(on ==false)

// keep reading cin



I don't believe that this is completely correct so can someone show me

how this code should be presented?



2. Print what is read to the standard output

I can only imagine this to be cout << ? But am lost from here



3. Reset the stream so it is valid before returning the stream

This section of the problem again defeats me.



Can anyone help with this function?









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6KSh

View all the progranning help forums at:

http://ift.tt/1dP9txN

pointer to a vector

Newsgroup: comp.lang.c++

Subject: pointer to a vector

From: "A" <a@...>

Date: Wed, 12 Feb 2014 20:46:12 +0100



There are 2 vectors each one having a structure



struct MyStruct

{

int a;

std::string b;

}



std::vector<MyStruct> v1;

std::vector<MyStruct> v2;



Now I want a pointer to which one I will use... v1 or v2



std::vector<MyStruct> *v = (condition)? &v1 : &v2;



Finally I access it using:



for (unsigned i = 0; i < v->size(); i++)

{

v->operator[](i).a = i + 1;

}



My lack of understanding here is:



a) does the above *v needs to be deleted? Isn't it just a pointer variable?

Or it works differently when it points to a vector? Just to be clear, I

don't actually need to delete v1 or v2. I just need to cleanup *v if

required.



b) what's the heap or stack or difference or advantage of them in relation

to the above?











via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6KBR

View all the progranning help forums at:

http://ift.tt/1dP9txN

about gets

Newsgroup: comp.lang.c++

Subject: about gets

From: mary8shtr@...

Date: Tue, 11 Feb 2014 09:22:12 -0800 (PST)



hi.I am writing a program.while i define some variable but program say this variable undefined.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/MC6KBH

View all the progranning help forums at:

http://ift.tt/1dP9txN

Tuesday, February 18, 2014

Flummoxed - Please Help!

Newsgroup: comp.lang.c++

Subject: Flummoxed - Please Help!

From: mrc2323@...

Date: Tue, 18 Feb 2014 12:40:26 -0700



I have the following (rather simple, I think) code which compiles but

executes in a bizarre way: the code in the subprogram is skipped when

called. 8<{{

Here's the code and the call to it I use:



string spellNumber(double value)

{

bool showThousands = false;

bool allZeros = true;

int ii, dPos, nn;

char wc;

string digits, temp;

ostringstream ossw;

static string builder;

ossw.str("");

ossw << value;

digits = ossw.str();

dPos = digits.find('.');

if(dPos != string::npos) digits.erase(dPos);

nn = digits.length();

wc = digits.back();

for(ii = digits.length()-1; ii >= 0; ii--)

{

int ndigit = (int)(digits[ii]-'0');

int column = (digits.length()-(ii+1));

} // for

// more code to be added here

return builder;

}

...

spellNumber(123.45); // call the function



I have, of course the normal stdafx.h header and "use namespace

std;", and this is code from a small test program I use to debug new

functions and such. Many other programs and many thousands of lines of

code work fine, but this code is weird...and I can't see what's wrong

with it!

Please advise... TIA



---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/O7tKtA

View all the progranning help forums at:

http://ift.tt/1dP9txN

SMITHSONIAN SHUT DOWN FOR GOOD -- THE THRINAXODON TIMES REPORTS, YOU CALL OUT BULLSHIT

Newsgroup: comp.lang.c++

Subject: SMITHSONIAN SHUT DOWN FOR GOOD -- THE THRINAXODON TIMES REPORTS, YOU CALL OUT BULLSHIT

From: Apidium23 <apidium23@...>

Date: Tue, 18 Feb 2014 14:05:26 -0500



==============

>BREAKING NEWS

==============

>

SMITHSONIAN FINALLY SHUT DOWN AFTER YEARS OF CENSORSHIP, SCAMS AND CON

ARTISTRY.

>

THRINAXODON BLEW DOWN THE BUILDINGS, LIT IT ON FIRE AND HAD THE ASSHOLES

ARRESTED.

>

R. DAWKINS WAS THROWN IN THE DOGHOUSE, ONLY TO GET KILLED BY ANGRY

FELONS WHO WANTED PAYBACK FOR FRAMING THEM.

>

THRINAXODON DANCED ON DAWKINS' GRAVE, AND BURNED A FEW SMITHSONIAN

MAGAZINES.

>

=================================

EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN:



http://ift.tt/O7tKcQ



http://ift.tt/1cXKQzc



====================================



http://ift.tt/O7tKcU



===================================



THRINAXODON ONLY HAD THIS TO SAY:



"I..I...I...Can't believe it. This completely disproved Darwinian

orthodoxy."



===================================



THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING

WITH FEAR.



===========================

THESE ASSHOLES ARE GOING TO DIE:

THOMAS AQUINAS;

ALDOUS HUXLEY;

BOB CASANVOVA;

SkyEyes;

DAVID IAIN GRIEG;

MARK ISAAK;

JOHN HARSHAM;

RICHARD NORMAN;

DR. DOOLITTLE;

CHARLES DARWIN;

MARK HORTON;

ERIK SIMPSON;

HYPATIAB7;

PAUL J. GANS;

JILLERY;

WIKI TRIK;

THRINAXODON;

PETER NYIKOS;

RON OKIMOTO;

JOHN S. WILKINS

===========================



THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A

HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT

THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD

TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY

FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep

people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS

SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That

is a myth, for people to believe in science." THRINAXODON PLANS TO

BRING DOOM TO SCIENCE, ITSELF.



============================



THRINAXODON IS NOW ON TWITTER.



======================================

>

THRINAXODON WAS AWARDED

US$100,000,000,000,000,000,000,000,000,000,000,000 ,000,000,000,000,000,000

DOLLARS FOR HIS BRAVE EFFORTS IN SHUTTING DOWN THE EVOLUTIONARY SCAMS.

--

Apidium23:



http://ift.tt/1cXKPLR









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/O7tKcW

View all the progranning help forums at:

http://ift.tt/1dP9txN