|
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?
|
|
|
|
|
Any help on this please
I Need to resolve this issue very urgently
|
|
|
|
|
varchar(50) is a database type, not a C++ type. What's the type of the data called "Value" that your code is using?
--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
|
|
|
|
|
its std::string
i also tried with std::wstring
|
|
|
|
|
Then why are you trying to convert to _bstr_t and back, when a simple assignment to your string variable will do?
--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
|
|
|
|
|
I have a tab control and with a set of CDialogImpls (WS_CHILD) for each page (swap them in and out depending on what page is selected). With XP themes turned on, the background of these panes needs to be the same color as the tab control (which is different than the standard dialog background). The problem is that my little panes are drawing with the standard dialog background instead of the tab control background. It looks really ugly. I haven't had this issue with MFC apps, only WTL. I've tried a numerous set of flags on the dialog (including transparent) to no avail. Does anyone know of the correct way to set these dialog so that they work?
|
|
|
|
|
i have created an ATL Dll "Simple_ATL.dll" having one function "AddNumbers(long Num1, long Num2, long *ReturnVal)",how can i use this function in asp,so that i can send the parameters from asp page?Can any one help me Please?
Thanks in advance
|
|
|
|
|
Something like this:
Dim obj, i<br />
Set obj = Server.CreateObject("Simple_ATL.NumberAdder")<br />
i = obj.AddNumbers(2,3)
|
|
|
|