Tuesday, January 26, 2010

comp.lang.c++ - 25 new messages in 15 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* How to get all possible substrings - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/308df61293b64874?hl=en
* ◈•_•◈wholesale cheap fashionable Jeans etc at www.ecyaya.com - 2 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/54505abb39407fcf?hl=en
* ♬♪♫ ♪<Paypal Payment> Cheap price wholesale LV Shoes at www.fjrjtrade.com -
1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/2efe012b993274bc?hl=en
* memory leaks - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/d9b20823062f2cb3?hl=en
* Support for export keyword ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/0878ed0c9c1ca584?hl=en
* U++ 1952 released - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/3f4ae5bb2f397202?hl=en
* casting from void* to const char * - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/13e7eac70fd0d709?hl=en
* ۞_۞free shipping wholesale low price nike shox shoes and ed hardy Jeans etc (
www.ecyaya.com) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/4a1a06e6e0fe3313?hl=en
* Customers Why ? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/6f471ef6a299d2e5?hl=en
* Again substrings and so on - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/736557e5175db0ba?hl=en
* Type of elements of std::string - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.c++/t/b6aba4785e69df38?hl=en
* Style guides for C and/or C++ - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/3543d1f01ca9b305?hl=en
* Memory contents mysteriously changing - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/d3d7f50cba06cf27?hl=en
* generate rand number - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c++/t/fcb11e63c73e0db8?hl=en
* Generate a random number - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c++/t/dd36f1e5144c1857?hl=en

==============================================================================
TOPIC: How to get all possible substrings
http://groups.google.com/group/comp.lang.c++/t/308df61293b64874?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Jan 26 2010 12:08 am
From: "crimaniak@googlemail.com"


On 26 янв, 11:04, "criman...@googlemail.com"
<criman...@googlemail.com> wrote:
> Something like this:
>
> $fullLength=strlen($string);
> for($begin=0;$begin<$fullLength;++$begin)
>  for($l=$fullLength-$begin;$l>0;--$l)
>   echo substr($string,$begin,$l)."\n";

Oh, no! I was in PHP conference now and this is result. %-)


== 2 of 2 ==
Date: Tues, Jan 26 2010 12:32 am
From: tonydee


On Jan 26, 9:14 am, Robert Reno <nebnetjeru...@gmail.com> wrote:
> Hello,
>
> I've been searching for some way to get all possible substrings out of
> an input string.  I've found information and scripts on suffix trees,
> but the examples I found only return an array of suffixes (hence the
> name I guess)...that is, substrings from progressively splitting off
> an initial letter from the string.  Has anyone run across a C++
> implementation of perl's String::Splitter function?  That's the kind
> of functionality that I'm looking for.

Have a look at boost's tokenize library.

Cheers,
Tony

==============================================================================
TOPIC: ◈•_•◈wholesale cheap fashionable Jeans etc at www.ecyaya.com
http://groups.google.com/group/comp.lang.c++/t/54505abb39407fcf?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Jan 26 2010 12:31 am
From: hero


◈•_•◈wholesale cheap fashionable Jeans etc at www.ecyaya.com


wholesale cheap Affliction Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Ed Hardy Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Armani Jean with high quality and low price at www.ecyaya.com

wholesale cheap Christian Audigier Jean with high quality and low
price at www.ecyaya.com

wholesale cheap Akademiks Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Bape Jean with high quality and low price at www.ecyaya.com

wholesale cheap Black Label Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Coogi Jean with high quality and low price at www.ecyaya.com

wholesale cheap Crown Holder Jean with high quality and low price at
www.ecyaya.com

wholesale cheap D&G Jean with high quality and low price at www.ecyaya.com

wholesale cheap Diesel Jean with high quality and low price at www.ecyaya.com

wholesale cheap Ecko Unltd Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Evisu Jean with high quality and low price at www.ecyaya.com

wholesale cheap G-Star Jean with high quality and low price at www.ecyaya.com

wholesale cheap Gucci Jean with high quality and low price at www.ecyaya.com

wholesale cheap Iceberg Jean with high quality and low price at www.ecyaya.com

wholesale cheap Jack&Jones Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Justcavalli Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Kanji Jean with high quality and low price at www.ecyaya.com

wholesale cheap LEVI'S Jean with high quality and low price at www.ecyaya.com

wholesale cheap LRG Jean with high quality and low price at www.ecyaya.com

wholesale cheap LV Jean with high quality and low price at www.ecyaya.com

wholesale cheap Rock Jean with high quality and low price at www.ecyaya.com

wholesale cheap True Relig Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Versace Jean with high quality and low price at www.ecyaya.com

== 2 of 2 ==
Date: Tues, Jan 26 2010 12:31 am
From: hero


◈•_•◈wholesale cheap fashionable Jeans etc at www.ecyaya.com


wholesale cheap Affliction Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Ed Hardy Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Armani Jean with high quality and low price at www.ecyaya.com

wholesale cheap Christian Audigier Jean with high quality and low
price at www.ecyaya.com

wholesale cheap Akademiks Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Bape Jean with high quality and low price at www.ecyaya.com

wholesale cheap Black Label Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Coogi Jean with high quality and low price at www.ecyaya.com

wholesale cheap Crown Holder Jean with high quality and low price at
www.ecyaya.com

wholesale cheap D&G Jean with high quality and low price at www.ecyaya.com

wholesale cheap Diesel Jean with high quality and low price at www.ecyaya.com

wholesale cheap Ecko Unltd Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Evisu Jean with high quality and low price at www.ecyaya.com

wholesale cheap G-Star Jean with high quality and low price at www.ecyaya.com

wholesale cheap Gucci Jean with high quality and low price at www.ecyaya.com

wholesale cheap Iceberg Jean with high quality and low price at www.ecyaya.com

wholesale cheap Jack&Jones Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Justcavalli Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Kanji Jean with high quality and low price at www.ecyaya.com

wholesale cheap LEVI'S Jean with high quality and low price at www.ecyaya.com

wholesale cheap LRG Jean with high quality and low price at www.ecyaya.com

wholesale cheap LV Jean with high quality and low price at www.ecyaya.com

wholesale cheap Rock Jean with high quality and low price at www.ecyaya.com

wholesale cheap True Relig Jean with high quality and low price at
www.ecyaya.com

wholesale cheap Versace Jean with high quality and low price at www.ecyaya.com


==============================================================================
TOPIC: ♬♪♫ ♪<Paypal Payment> Cheap price wholesale LV Shoes at www.fjrjtrade.
com
http://groups.google.com/group/comp.lang.c++/t/2efe012b993274bc?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 12:38 am
From: "www.fjrjtrade.com"


♬♪♫ ♪<Paypal Payment> Cheap price wholesale LV Shoes at www.fjrjtrade.com


Welcome to visit www.fjrjtrade.com

Men size 40,41,42,43,44,45,46. Women size 36,37,38,39,40.

High quality wholesale Air Force One shoes, Nike Jordan, Nike,Air Max,
Nike Shox, UGG Shoes, Puma Shoes, Nike shoes, Adidas Shoes, Christian
Louboutin, Chanel Shoes, Coach Shoes, D&G Shoes, Dior Shoes, ED Hardy
Shoes, Evisu Shoes, Fendi Shoes, AFF shoes, Bape shoes, Gucci Shoes,
Hogan shoes, Bikkembergs Shoes, Dsquared Shoes, LV Shoes, Timberland
Shoes, Boss shoes, Versace Shoes, Prada Shoes, Lacoste Shoes, Mauri
Shoes, DC shoes ect. More other shoes at website www.fjrjtrade.com


Cheap wholesale LV Shoes

http://www.fjrjtrade.com/940-LV-Shoes.html

Cheap wholesale LV Boots

http://www.fjrjtrade.com/1877-LV-Boots.html

Cheap wholesale LV Men High Shoes

http://www.fjrjtrade.com/1878-LV-Shoes-Man-High.html

Cheap wholesale LV Men Shoes

http://www.fjrjtrade.com/1619-LV-Shoes-Man.html

Cheap wholesale LV Women Shoes

http://www.fjrjtrade.com/1617-LV-Shoes-Woman.html

Cheap wholesale LV Kids' Shoes

http://www.fjrjtrade.com/1618-LV-Shoes-Kids.html


More Others Shoes At WEBSITE:
http://www.fjrjtrade.com

==============================================================================
TOPIC: memory leaks
http://groups.google.com/group/comp.lang.c++/t/d9b20823062f2cb3?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Jan 26 2010 1:12 am
From: Nick Keighley


On 25 Jan, 16:14, "Alf P. Steinbach" <al...@start.no> wrote:
> * Larry:

> > #define _CRT_SECURE_NO_WARNINGS
>
> Don't do that.

why?

It suppresses some irritating MS warnings. Are you saying don't
suppress the warnings or don't embed such MSisms in your source (for
instance use something in the build system like
-D?)


== 2 of 2 ==
Date: Tues, Jan 26 2010 2:16 am
From: Richard Herring


In message <4b5df6a2$0$1141$4fafbaef@reader1.news.tin.it>, Larry
<dontmewithme@got.it> writes
>"Thomas J. Gritzan" <phygon_antispam@gmx.de> ha scritto nel messaggio
>news:hjkru0$o2i$1@newsreader3.netcologne.de...
>
>>> struct Buffer
>>> {
>>> public:
>>> vector<char> vChar;
>>> int bufferLength;
>>> int bytesRecorded;
>>> int user;
>>> Buffer() : bytesRecorded(0), bufferLength(0), user(0) { };
>>> };
>
>So I think the following is the only way not to have memory leaks:

[...]
>
>struct Buffer
>{
>public:
>char payload[4096];

[...]
>
>where payload is set to 4096 bytes long. Indeed it's going to hold less
>data but this way I can make sure it can hold from 0 to 4095
>bytes...the other filed in the struct will store how long payload
>actually is!

<sigh>

And when you change the program so it needs 4097 bytes, you will get
undefined behaviour. What is so hard about using vector or string to
manage that memory, as everyone else is advising you?

USE A VECTOR.

--
Richard Herring

==============================================================================
TOPIC: Support for export keyword ?
http://groups.google.com/group/comp.lang.c++/t/0878ed0c9c1ca584?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 1:54 am
From: Vladimir Jovic


Jerry Coffin wrote:
> In article <4b56ed82$0$283$14726298@news.sunsite.dk>,
> terminatorul@gmail.com says...
>
> [ ... ]
>
>> Why do people bother to even mention/talk about such pathetic excuses
>> for a compiler ?
>
> Producing C as its output doesn't make Comeau any less a compiler
> than producing object code would. Your claim only shows that you
> don't know what you're talking about.
>
> From a practical viewpoint, its use of C as an intermediate language
> isn't normally visible at all. You run the compiler, and you get an
> executable file as output.

Sorry for my ignorance, but how do you debug with such compiler?

==============================================================================
TOPIC: U++ 1952 released
http://groups.google.com/group/comp.lang.c++/t/3f4ae5bb2f397202?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 2:01 am
From: Koldo


Website: http://www.ultimatepp.org
Download: http://code.google.com/p/upp-mirror/downloads/list

U++ is BSD licensed C++ cross-platform rapid application development
suite focused on programmers productivity without sacrificing
runtime performance.

What is new in version 1952:

TheIDE:
* Improved installation in Win32 with support for the latest Win32
SDK.
* Helpsystem has vastly improved searching capabilities.
* Build process now supports new link options - Posix releases now use
"gc-sections" linker option to dramatically reduce the size of
resulting
binaries (up to 40%).

CtrlLib:
* File selector (FileSel class) got networking support in Win32.
* TrayIcon in X11 now supports notifications.
* TopWindow in X11 now supports SetAlphs.

Painter:
* Image rescaling algorithm was improved for better downscaling.

Core:
* Containers now have a new debugging utility to resolve pick semantic
errors.

==============================================================================
TOPIC: casting from void* to const char *
http://groups.google.com/group/comp.lang.c++/t/13e7eac70fd0d709?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 2:26 am
From: Richard Herring


In message <4b5e56aa$0$1132$4fafbaef@reader3.news.tin.it>, Larry
<dontmewithme@got.it> writes
>
>"Larry" <dontmewithme@got.it> ha scritto nel messaggio
>news:4b5e2ccd$0$1144$4fafbaef@reader1.news.tin.it...
>
>> I have the following struct:
>
>no problem anymore. I have changed to this:
>
>#include <algorithm>
>
>struct buffer
>{
>char data[1024];
>int bytesRecorded;
>bool flag;
>buffer(const char * data_, const int bytesRecorded_, const bool flag_) :
>bytesRecorded(bytesRecorded_), flag(flag_)
>{
> std::copy(data_, data_ + (bytesRecorded_ * sizeof(char)), data);

That's wrong.

(OK, it doesn't actually matter here, because sizeof(char) is 1 by
definition, but your code is evidence of a number of misconceptions
which will bite you later:)

If bytesRecorded really is a count of bytes, you shouldn't be
multiplying it by sizeof(anything), because it's already a measure of
size.

If bytesRecorded is actually a badly-named count of objects, you still
shouldn't be multiplying it by sizeof(anything) because std::copy copies
objects, not bytes, and its arguments are iterators to objects, not
pointers to memory.

And you should be replacing data and bytesRecorded by a
std::vector<char>, anyway, and using its initializer to insert the
data..

>}
>};
>
>thanks

PS Most people who use the trailing-underscore convention do it the
other way round: member variables get the suffix, local variables and
parameters don't.
--
Richard Herring

==============================================================================
TOPIC: ۞_۞free shipping wholesale low price nike shox shoes and ed hardy Jeans
etc (www.ecyaya.com)
http://groups.google.com/group/comp.lang.c++/t/4a1a06e6e0fe3313?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 3:32 am
From: Robbin-Lime


On Jan 25, 11:20 pm, hero <ecyaya...@163.com> wrote:
> ۞_۞free shipping wholesale low price nike shox shoes and ed hardy
> Jeans etc (www.ecyaya.com)
>
> Footwear (paypal payment)(www.ecyaya.com)
>
> Paul Smith shoes
>
> Jordan shoes
>
> Bape shoes  (paypal payment)(www.ecyaya.com)
>
> Chanel shoes (paypal payment)(www.ecyaya.com)
>
> D&G shoes
>
> Dior shoes (paypal payment)(www.ecyaya.com)
>
> ED hardy shoes
>
> Evisu shoes
>
> Fendi shoes
>
> Gucci shoe  (paypal payment)(www.ecyaya.com)
>
> Hogan shoes (paypal payment)(www.ecyaya.com)
>
> Lv shoes
>
> Prada shoes (paypal payment)(www.ecyaya.com)
>
> Timberland shoes
>
> Tous shoes  (paypal payment)(www.ecyaya.com)
>
> Ugg shoes
>
> Ice cream shoes  (paypal payment)(www.ecyaya.com)
> Sebago shoes (paypal payment)(www.ecyaya.com)
>
> Lacoste shoes
>
> Air force one shoes (paypal payment)(www.ecyaya.com)
>
> TODS shoes
>
> AF shoes  (paypal payment)(www.ecyaya.com)
>
> cheap EVISU jeans wholesale  www.ecyaya.com
>
> cheap ED hardy jeans wholesale
>
> cheap COOGI jeans wholesalewww.ecyaya.com
>
> cheap GINO GREEN GLOBAL jeans wholesale
>
> cheap LACOSTE jeans wholesalewww.ecyaya.com
>
> cheap G-STAR jeans wholesalewww.ecyaya.com
>
> cheap KED ROBOT jeans  wholesale
>
> cheap RED MONKEY jeans wholesalewww.ecyaya.com
>
> cheap ADIDAS jeans wholesalewww.ecyaya.com
>
> cheap BBC jeans wholesale
>
> cheap BOSS jeans wholesalewww.ecyaya.com
>
> cheap LRG jeans wholesale
>
> cheap HELEN jeans wholesalewww.ecyaya.com
>
> cheap JUICY jeans wholesale
>
> cheap THE CROUN HOLDER jeans  wholesalewww.ecyaya.com
>
> cheap SMET jeans  wholesalewww.ecyaya.com
>
> cheap SEVEN jeans  wholesalewww.ecyaya.com
>
> cheap TRUN NORTH FACE jeans wholesale
>
> cheap children jeans wholesalewww.ecyaya.com
>
> cheap ARMANI jeans wholesalewww.ecyaya.com
>
> cheap BAPE jeans  wholesale
>
> cheap LEVIS jeans wholesalewww.ecyaya.com
>
> cheap ANTIK jeans wholesalewww.ecyaya.com
>
> cheap true religion jeans wholesalewww.ecyaya.com

Why do youjust have so many customers ?

==============================================================================
TOPIC: Customers Why ?
http://groups.google.com/group/comp.lang.c++/t/6f471ef6a299d2e5?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 3:33 am
From: Robbin-Lime


http://groups.google.com/group/home_business_express1/browse_thread/thread/a7d7e11e5c080900?hl=en

==============================================================================
TOPIC: Again substrings and so on
http://groups.google.com/group/comp.lang.c++/t/736557e5175db0ba?hl=en
==============================================================================

== 1 of 3 ==
Date: Tues, Jan 26 2010 3:38 am
From: Vicent Giner-Bosch


Sorry for asking about the same subject again, but I am a bit lost.

I would like to ask you about standard or usual ways to manage with
files or strings, specially when getting input data and writing output
from an algorithm.

I mean: which structures, data types or classes? Which standard ways
to read/write from/on files?

I've read some tutorials that deal the standard C I/O and string
(string.h) libraries, but specially when managing strings, I am a bit
lost: Are there methods or functions to get substrings from a string,
or to take "spaces" ("blanks") away (a typical "wrap" function)??

About reading data from a text file, I think this is called "parsing".
Is there any "parsing" library???

Sorry if my questions are too naive, but I am a beginner.

Thank you very much in advance!

--
Vicent


== 2 of 3 ==
Date: Tues, Jan 26 2010 5:18 am
From: Victor Bazarov


Vicent Giner-Bosch wrote:
> Sorry for asking about the same subject again, but I am a bit lost.
>
> I would like to ask you about standard or usual ways to manage with
> files or strings, specially when getting input data and writing output
> from an algorithm.

There are probably as many answers as there are people you ask.

> I mean: which structures, data types or classes? Which standard ways
> to read/write from/on files?

'istream', 'ostream', 'ifstream', 'ofstream', 'string'...

> I've read some tutorials that deal the standard C I/O and string
> (string.h) libraries,

Why have you been reading C tutorials when your language is C++? Get
yourself a copy of "The C++ Standard Library: A Tutorial and a
Reference" by Josuttis.

> but specially when managing strings, I am a bit
> lost: Are there methods or functions to get substrings from a string,

'std::string' has the 'substr' member.

> or to take "spaces" ("blanks") away (a typical "wrap" function)??

Not sure what 'a typical "wrap" function' is, but anything can be
removed from a 'string' by means of 'erase' member function.

> About reading data from a text file, I think this is called "parsing".
> Is there any "parsing" library???

I am sure there are quite a few. All depends on what kind of "parsing"
you need.

> Sorry if my questions are too naive, but I am a beginner.

It would seem that you need some basic course on C++ before you embark
on writing or even using a parser. It's hard to advise anything without
knowing your level. What C++ books have you read so far?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


== 3 of 3 ==
Date: Tues, Jan 26 2010 6:26 am
From: Christian Hackl


Vicent Giner-Bosch ha scritto:

> I've read some tutorials that deal the standard C I/O and string
> (string.h) libraries, but specially when managing strings, I am a bit
> lost: Are there methods or functions to get substrings from a string,
> or to take "spaces" ("blanks") away (a typical "wrap" function)??

Boost has a string algorithm library:
http://www.boost.org/doc/libs/1_41_0/doc/html/string_algo.html

It adds a lot of useful string functions which standard C++ does not
provide.

In particular, have a look at the following for string trimming:
http://www.boost.org/doc/libs/1_41_0/doc/html/string_algo/usage.html#id1701360

> About reading data from a text file, I think this is called "parsing".

No, these are different things. You can parse text from sources other
than files, and you can read text from a file without parsing it.


--
Christian Hackl
hacki@sbox.tugraz.at

Milano 2008/2009 -- L'Italia chiamò, sì!

==============================================================================
TOPIC: Type of elements of std::string
http://groups.google.com/group/comp.lang.c++/t/b6aba4785e69df38?hl=en
==============================================================================

== 1 of 3 ==
Date: Tues, Jan 26 2010 3:54 am
From: Leslaw Bieniasz


On Mon, 25 Jan 2010, Richard Herring wrote:

> Do you understand *why* get() returns int, and what subset of possible int
> values it can return? That's the point of my question below:

Yes, that's the point. I do not understand why get() returns int. If
get() is supposed to read successive bytes, then I would expect it
to return char. What are the cases when it returns int?
Is this EOF, or what else?

> Good. Then you should be reading an int from get(), separating out the values
> that represent characters from those which don't, appending the chars to the
> string and doing something else with the non-chars.

Do you mean casting from int to char? This removes the warning message
and from my brief test seems to work OK, but how can I be sure if
it always works correctly?

Leslaw


== 2 of 3 ==
Date: Tues, Jan 26 2010 5:33 am
From: Richard Herring


In message <Pine.GHP.4.64.1001261249020.17854@kinga.cyf-kr.edu.pl>,
Leslaw Bieniasz <nbbienia@cyf-kr.edu.pl> writes
>On Mon, 25 Jan 2010, Richard Herring wrote:
>
>> Do you understand *why* get() returns int, and what subset of
>>possible int values it can return? That's the point of my question
>>below:
>
>Yes, that's the point. I do not understand why get() returns int. If
>get() is supposed to read successive bytes, then I would expect it
>to return char. What are the cases when it returns int?
>Is this EOF, or what else?

EOF. Read the documentation.
>
>> Good. Then you should be reading an int from get(), separating out
>>the values that represent characters from those which don't,
>>appending the chars to the string and doing something else with the
>>non-chars.
>
>Do you mean casting from int to char?

Or any other form of conversion.

>This removes the warning message
>and from my brief test seems to work OK, but how can I be sure if
>it always works correctly?

By only converting when you know that the value is in the range valid
for char.

--
Richard Herring


== 3 of 3 ==
Date: Tues, Jan 26 2010 6:52 am
From: Jerry Coffin


In article <Pine.GHP.4.64.1001251045190.17688@kinga.cyf-kr.edu.pl>,
nbbienia@cyf-kr.edu.pl says...
>
> Hi,
>
> What is actually the type of elements of std::string?

char. Specifically, the definition of std::string looks like:
typedef basic_string<char> string;

> I am trying to read the elements from a stream, in the following
> way:
>
> std::string str = "";
> int c;
>
> // Read string size
> int n;
> is >> n;
>
> // Read string
> for(int i=0; i<n; i++)
> {
> c = is.get();
> str += c;
> }

Hmm...I think I'd do this more like:

int n;
is >> n;

std::string str(n, ' ');
is.read(&str[0], n);

This should eliminate the warning(s), and if there's a difference in
efficiency, I'd guess it's more likely to favor this version than the
other. In theory, this isn't entirely portable -- the current
standard doesn't guarantee that std::string will use contiguous
storage for the characters. In reality, current implementations do
use contiguous storage, and the next version of the standard will
require it, so there's not really much chance of a new implementation
that uses non-contiguous storage.

--
Later,
Jerry.

==============================================================================
TOPIC: Style guides for C and/or C++
http://groups.google.com/group/comp.lang.c++/t/3543d1f01ca9b305?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 5:05 am
From: Vladimir Jovic


Timothy Madden wrote:
> int main()
> {
> int iResult = 0;
>
> if
> (
> iResult <= 10
> &&
> iResult >= -2
> &&
> iResult == 0
> )
> {
> cout << "Right result";
> cout << endl;
>
> return iResult;
> }
> else
> ::CreateWindow
> (
> szClassName,
> szTitle,
> dwStyle,
> xPos,
> yPos,
> cxWidth,
> cxHeight,
> hwndParent
> );
>
> return -1;
> }
>

I see you haven't been bit by this bug-type yet.

I would write this code snippet like this:


int main()
{
int iResult = 0;

if
(
iResult <= 10
&&
iResult >= -2
&&
iResult == 0
)
{
cout << "Right result";
cout << endl;

return iResult;
}
else
{
::CreateWindow
(
szClassName,
szTitle,
dwStyle,
xPos,
yPos,
cxWidth,
cxHeight,
hwndParent
);
}

return -1;
}


==============================================================================
TOPIC: Memory contents mysteriously changing
http://groups.google.com/group/comp.lang.c++/t/d3d7f50cba06cf27?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 5:11 am
From: Victor Bazarov


Mark wrote:
> On Jan 23, 11:52 am, LR <lr...@superlink.net> wrote:
>> LR wrote:
>>> Mark wrote:
>> Sorry, I forgot to ask about Silo.
>>
>> Is this a C or a C++ library?
>>
>> LR
>
>
> Good question. As best I can tell by looking at the header file it's
> a C library that is written to be compatible with C++.

I personally don't think it matters.

> Will I run into memory allocation problems if I mix C and C++?

Not usually. Unless you try to 'delete' the pointer you got from
'malloc' (even indirectly), and it's a pointer to a class with a d-tor
or any members that might have a d-tor... Anyway, there is always more
than one way to get your program to have undefined behaviour, but it
does not stem from mixing languages. You can do it in a pure C++
program, it's simple, really.

> And is
> there a way to check whether this is happening?

Whether memory problems are due to mixing languages? I don't think so.

Now, considering Kaz's and Pete's replies, try to find a good tool that
would help you identify the cause of the problem. The variations on the
cause are few. An array overrun, a dangling pointer, an uninitialised
pointer, an invalid (usually C-style) cast. That's probably not the
complete list, but close. Along with Kaz's recommendation of
'valgrind', I'd try turning up the warning level on your compiler,
running PC-lint on your source, and simplifying the code to try to
identify the place where it might happen: if you suspect SILO, start by
using their code samples first (supposing they work), then gradually add
to them what you've tested and verified as working (your code)...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

==============================================================================
TOPIC: generate rand number
http://groups.google.com/group/comp.lang.c++/t/fcb11e63c73e0db8?hl=en
==============================================================================

== 1 of 3 ==
Date: Tues, Jan 26 2010 5:54 am
From: "Larry"


Hi,

I need to create a tiny function to generate a random number ranging
from: 1000000 to 9999999. Also, the number should be unique even if I call
the function 100 times in a second...can it actually be done?

All I know for the moment is this: srand(time(0)): rand(); but it is not
that great :-(

thanks

== 2 of 3 ==
Date: Tues, Jan 26 2010 6:36 am
From: "osmium"


"Larry" wrote:

> I need to create a tiny function to generate a random number ranging
> from: 1000000 to 9999999. Also, the number should be unique even if I call
> the function 100 times in a second...can it actually be done?
>
> All I know for the moment is this: srand(time(0)): rand(); but it is not
> that great :-(

For the range problem, look at the FAQ for the C language. You can find the
FAQ via google.

For the uniqueness problem use google to look for the magic buzzword
"shuffle",


== 3 of 3 ==
Date: Tues, Jan 26 2010 6:50 am
From: "osmium"


osmium wrote:

> "Larry" wrote:
>
>> I need to create a tiny function to generate a random number
>> ranging from: 1000000 to 9999999. Also, the number should be unique
>> even if I call the function 100 times in a second...can it actually
>> be done? All I know for the moment is this: srand(time(0)): rand(); but
>> it is
>> not that great :-(
>
> For the range problem, look at the FAQ for the C language. You can
> find the FAQ via google.
>
> For the uniqueness problem use google to look for the magic buzzword
> "shuffle",

On further thought. If you need a huge number of numbers, say over 100,000,
the shuffle solution may not be a good one. In that case, establish a
vector and put each number in it as chosen. The vector will grow
automatically to "infinite" length, as needed. Examine the vector before
issuing each number. The search will get slower and slower as time goes on
but you may be able to clever that up a bit to handle that.

==============================================================================
TOPIC: Generate a random number
http://groups.google.com/group/comp.lang.c++/t/dd36f1e5144c1857?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Jan 26 2010 6:50 am
From: Robbin-Lime


I'd like to generate a random number to observe behaviors of intrusive
and leeches like programs in my own computers, I discovered 2, both of
which relates to my named blk IBM server. Really intensify my
eyestrain everytime I see them their but undeleteable.
These I can find a bunch in stores near the park. I can also wish to
manually adjust them instead by the way

== 2 of 2 ==
Date: Tues, Jan 26 2010 6:53 am
From: Robbin-Lime


On Jan 26, 9:50 pm, Robbin-Lime <gentlerob...@gmail.com> wrote:
> I'd like to generate a random number to observe behaviors of intrusive
> and leeches like programs in my own computers, I discovered 2, both of
> which relates to my named blk IBM server. Really intensify my
> eyestrain everytime I see them their but undeleteable.
> These I can find a bunch in stores near the park. I can also wish to
> manually adjust them instead by the way

I have no experience in writing a debugger to reveal their internal
behavior "(


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

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: