|
You need to assign the iterator to something valid before using it.
std::vector<int> v;
std::vector<int>::iterator pBegin = v.begin();
while ( pBegin != v.end() )
{
++it;
}
or
if ( pBegin != v.end() )
{
}
Watched code never compiles.
|
|
|
|
|
|
std::vector<int>::iterator pIter = v.end();
//do Some operation on pIter
if ( pIter != v.end() )
{
// do something
}
Is the above logic make sense?
|
|
|
|
|
Checking it against NULL is wrong. It's an implementation detail that it works in vc6 (because raw pointers are used, amongst other implementation specific details). Iterators are not required be pointers, in fact vectors are one of the few containers where they can do the job and as you've discovered even then they are not the only option.
Steve
|
|
|
|
|
Hi all,
I want to map logical drive to its physical drive value i.e. if i give c: it should tell its hard disk number and partition number. For example if i give C: it should give \Device\HardDiskVolume1. For doing so i have used QueryDosDevice but it is not giving me correct answer. Here is my code
CString text;
GetDlgItemText(IDC_EDIT1,text);
TCHAR szBuffer[MAX_PATH];
bool bIsFloppy = false;
if (QueryDosDevice(text, szBuffer, MAX_PATH) > 0)
{
CString buffer = szBuffer;
AfxMessageBox(buffer);
}
But my code is giving incorrect result \Device\HardDiskVolume11
Can anybody please tell me what i am doing wrong?
|
|
|
|
|
Your code is not incorrect; volume names are assigned internally by Windows and do not necessarily follow the order that you expect. There is lots of information in MSDN here[^] that helps to explain it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
there are a struct:
struct _Tag
{
Type a;
Type b;
};
I just want to set the the type of a and b at runtime(i.e. set a to int and later set a to string within the same struct _Tag), don't tell me to use templates. For templates don't meet my requirements.
Another question:
There is a C++ statement:
AfxMessageBox(_T("Hello, world!")) ;
what I want to do is put the statement above into a
CString variable str . That is:
CString str = _T("AfxMessageBox(_T(\"Hello, world!\"));");
I want to execute the statement stored in str later, so that the statement just like the ACTUAL MFC EXECUTABLE STATEMENT I typed.
I wonder whether C++ support such operations.
Any help will be appreciated!
|
|
|
|
|
|
Thanks for reply!
You solved my first question.
But how about the second question?
|
|
|
|
|
Falconapollo wrote: I wonder whether C++ support such operations.
Nope, there is NO support for such operations. You have to build yourself a parser or embed a script engine in your application (for instance you may host, via <code> COM, VBScipt or JScript : have a look ath the following, bit dated, Codeproject article "Adding VBScript and JScript support in your C++ applications"[^]. Another nice option is Lua[^]).
Veni, vidi, vici.
|
|
|
|
|
1) Use a union.
2) You cant compile code at run time. What you can do is use function pointers so you can select the behaviour you want at run time.
==============================
Nothing to say.
|
|
|
|
|
I have developed one GUI in vb.net but now I want to use C as backend code along with MySql as database.
Is it possible to create such a application.
I have been using C and MySql under Fedora and I have my GUI ready in vb.net. Can you tell me how can I communicate these thing together?
For ex. I have add button on front end, when I click add button, and instead of defining functionality in vb.net I want to send input to C function and then C function will execute and return output.
|
|
|
|
|
Do you mean that you want the VB frontend running under windows to "do business" on a -most likely separate- machine running Fedora? If yes, i'd say, use a client-server aproach, run a server on the Fedora machine onto which your VB app connects and then sends commands (which are then executed by your C code) and receives results (created by your C code).
If you mean that you want the C code to also run on the windows machine, in my oppinion your best bet would be to create a DLL from your C code and then use it in a VB app with your frontend calling methods as needed.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Yes I want to use first approach means I will use client-server approach. But can you tell me how can I do this?
|
|
|
|
|
Look into sockets under linux[^] and sockets under windows[^], i'd use TCP/IP or UDP depending on your needs. For VB related questions, target the VB forums here on CodeProject.
For the basic client-server aproach[^], Google is your friend.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I use GDI or DirectX way to capture the screen shot.
In windows xp or 2003, the picture is normal, but in some win7 (32 or 64) system:
It is the desktop's image or whole black , when running a full screen game.
what's wrong ?
and how to fix it ?
|
|
|
|
|
Hi.
I was just wondering what exactly does ShowWindow(...) call (WM_ ???) ? I looked around but it does not seem that it calls WM_SHOWWINDOW. I want to send this message to another application with SW_HIDE etc...
Thanks in advance.
Stan the man
|
|
|
|
|
I think you will find this page[^] and this one[^] give the details.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
If i am correct then you ran into the same misunderstanding i did long long time ago. You don't show or hide a window by sending it WM_SHOWWINDOW . It geta this message when it is shown or hidden, but not to show or hide it. As far as i know ShowWindow basically sets the WS_BISIBLE style of the given window, it might also perform some additonal tasks like redrawing, sending messages, don't know the rest.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Hi.
I will try this. I think that is what I have been mixed up about. Thanks for the insight.
Stan the man
|
|
|
|
|
I find one empty struct. I donot know what effect it make.
struct nat{};
modified 2-Apr-12 12:46pm.
|
|
|
|
|
Its a simple way to tell the compiler that a structure exists. Just like we define function. In case of function we define the function name in the header file and write the body in the source file. but in case of struct the situation is little different.
here is an example:
struct A
{
int a, b;
struct B *Point_to_B;
}
struct B
{
int a;
int b;
struct A *Point_to_A;
}
in the above example you will found a trouble. The trouble is including header file. No matter how you organize either struct A or struct B will be undefined. So if you do just like below it will solve your problem
struct A;
struct A
{
int a, b;
struct B *Point_to_B;
}
struct A;
struct B
{
int a;
int b;
struct A *Point_to_A;
}
|
|
|
|
|
If you look again, it's
struct nat{};
and not
struct nat;
it isn't a forward declaration.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I checked out this[^] file, it has this in it (as you said):
struct nat{};
then later on in this file i see things like:
template<class T>
struct add_reference<T&>
{
typedef T& type;
}; and
template<>
struct add_reference<void>
{
typedef nat &type;
};
As you see this last template specialization is a specialization for the add_reference template with void . Thus, i would say, nat is used to make template instantiation available with void . Just think about it, e.g. this:
add_reference<int> x;
Without the specialization with void and nat :
add_reference<void> x;
this obviously won't work, you can't have reference to void, you wouln't be able to instantiate this template using void. So they substitute the void & reference with nat & , the compiler will be happy and the programmer will be happy:
add_reference<void> x;
So i supose nat simply stands for something like: not a type, or somesuch.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
+5
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|