|
Thanks, Joaquín buddies!
I have seen several times the istream_iterator
is initialized with the ptrdiff_t parameter.
But why I can not use it here?
Cheers,
George
|
|
|
|
|
The standard set of parameters of istream_iterator is
template <
class T,
class charT = char,
class traits = char_traits<charT>,
class Distance = ptrdiff_t
> istream_iterator; So the ptrdiff_t parameter, if anywhere, should be in the fourth position. (Beware, VC++ 6.0 is non-standard in this respect and expects a maximum of three parameters.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín buddies!
I find out the definitions in VC6.0.
--------
template<class U, class E = char, class T = char_traits<E> >
class istream_iterator
: public iterator<input_iterator_tag, U, ptrdiff_t>
--------
So, if I want to use the parameter ptrdiff_t and read int from a file, how could I assign parameter? <int, ??, ptrdiff_t>? What should be the second parameter?
Thanks in advance,
George
|
|
|
|
|
So, if I want to use the parameter ptrdiff_t and read int from a file, how could I assign parameter?
What do you want to specify ptrdiff_t for?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín pal!
To tell the truth, I myself do not
understand why I should use ptrdiff_t.
I use it simply because I am reading
some codes of a project which is developed
from BC IDE and all the pieces of codes
uses the keyword.
Can you show me how to use ptrdiff_t
in my scenario?
Thanks in advance,
George
|
|
|
|
|
Ignore it; just use istream_iterator<int> . If you want to know more about the additional parameters of istream_iterator read some C++ reference, but usually you won't need them anyway.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
I will follow your advice.
Cheers,
George
|
|
|
|
|
Hi, everyone!
My STL tutorial says,
--------
Assignment through the same value of the iterator should happen only once.
ostream_iterator<int> r (cout);
*r = 0;
*r = 1;
is not a valid code sequence.
--------
But I tried the above code sample, it works OK!
The output is 0 and 1.
What is the meaning of the tutorial?
Thanks in advance,
George
|
|
|
|
|
You've hit undefined behavior. If VC++'s STL implementation happens to work this way, this is only sheer luck, and as you know good luck is something you'd better not count on
So, I suggest you stick to the standard and write:
...
*r++ = 0;
*r++ = 1;
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, Joaquín pal!
I am a newbie of STL. I do not understand
what is your meaning clearly. What means
"undefined behavior"? Can you give me a more
clarified and detailed description of my case?
Thanks in advance,
George
|
|
|
|
|
Undefined behavior means you're not doing things as required and the compiler can do anything it wishes (refusing to compile, show different behaviors in debug/release mode, crash in run-time, etc.)
The rule for output iterators is that you cannot assign a value to an interator more than once without incrementing between wrtie operations.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks, Joaquín buddies!
George
|
|
|
|
|
Hi, Joaquín buddies!
I have tried your codes. It works OK!
But I still do not understand what is the
theory of output iterator, like the following,
--------
Assignment through the same value of the
iterator should happen only once.
--------
I think my code must have some potential error as you
mentioned. But I do not know what the error is.
Can you explain it to me?
Thanks in advance,
George
|
|
|
|
|
Hi, everyone!
I meet with the following trouble when compiling the
following simple STL program.
The error message is, ostream_iterator undeclared.
My IDE is VC 6.0.
Here are the source codes,
--------
#include "iterator"
#include "iostream"
void main()
{
ostream_iterator<int> r (cout);
*r = 0;
}
--------
Thanks in advance,
George
|
|
|
|
|
|
Thanks, Michael buddies!
George
|
|
|
|
|
ostream_iterator is in the std namespace [^]. In short, a namespace is a scope of which contains one or more related functions/classes/structs. To use members of a namespace you either have to 'import' them (with the nasty using namespace std; --nasty because it pollutes the global scope...read the tutorial for more information) or explicitly prefix each one you use with the namespace's name.
The following should do what you want:
#include <iterator>
#include <iostream>
int main () {
std::ostream_iterator<int> r ( std::cout );
*r = 0;
}
My suggestion is that you read up on the STLs. There are many great books on the subject, as well as some excellent articles on this site.
cheers,
-B
|
|
|
|
|
Thanks, Ben buddies!
George
|
|
|
|
|
|
WTL7 can be used with ATL7 without problems. However, you might have to make some changes. For instance, the _Module thing has been done away with.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I think
#define _Module _AtlBaseModule
or
#define _Module (*_pAtlModule)
in your stdafx.h file will make it work.
|
|
|
|
|
Both of them don't work. The compile errors are:
#define _Module _AtlBaseModule
c:\wtl70\include\atldlgs.h(491): error C2039: 'ExtractCreateWndData' : is not a member of 'ATL::CAtlBaseModule'
#define _Module (*_pAtlModule)
c:\wtl70\include\atlctrls.h(1598): error C2039: 'GetResourceInstance' : is not a member of 'ATL::CAtlModule'
|
|
|
|
|
While iterating an ADO Recordset, I am reading a varchar (50) field from database and doing a cast to stl string in following way.
pRecordset->MoveFirst();
while (!pRecordset->adoEOF)
{
std::string homeAddress = (const char*) (_bstr_t) pRecordset->GetFields()->GetItem("HomeAddress")->Value;
// Doing some other stuff with string
pRecordset ->MoveNext();
}
HomeAddress field in database has quite a lot of records that have spaces embedded into them. I have seen that there is no problem until cast to const char*, but copying this into std::string sometimes get correct values and some times have garbage.
Initially I thought that It might be a problem for only records where it has space, but sometimes I am able to get correct value in std:string no matter it has space or not. I also tried replacing all the whitespace character with a space just to make sure that there is no null(\0) , but no luck.
Any help or tips on this would be highly appreciated
|
|
|
|
|
Anonymous wrote:
GetItem("HomeAddress")->Value
What type is Value ? Since that's the source of your data, that's the place to start looking. It needs to be a type that can be used to construct a _bstr_t for starters.
--Mike--
Looks like I picked the wrong week to stop sniffing glue.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
A little confused about you question on "What type is Value"
This HomeAddress is a varchar(50) column in the database. The code i copied is pretty much all i am doing to read from database and converting to a std::string. Is there anything i be missing here?
|
|
|
|