|
Hi, everyone!
I often puzzled about when to use const_iterator of vector
and when to use size_type of vector.
For example, in the following piece of code, we should use
const_iterator instead of size_type.
I want to know whether there are some concrete rules? Easy to
remember ones.
Source Code:
--------
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string>::const_iterator i;
vector<string> Buffer;
Buffer.push_back ("Hello");
i = Buffer.begin();
return 1;
}
--------
Thanks in advance,
George
|
|
|
|
|
You use size_type when you work with an index into the vector.
For access, you use operator[]
You use an iterator as a pointer into the vector.
For access you use operator->
So, in one sentence: They do similar things, but are absolutly not interchangeable.
I hope this helped
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Thanks, jhwurmbach buddy!
I have never used operator -> with const_iterator of
vector. I have just used * operator on it. Can you
show me an example about how to use operator -> with
const_iterator of vector?
regards,
George
|
|
|
|
|
The -> operator is used when the iterator references a struct or class . It's a short-hand notation for combination of * and . :
iter->member is same as
(*iter).member
|
|
|
|
|
Thanks, markkuk buddy!
I think when use const_iterator, the operator -> is used on
the iterator. And when use size_type, the operator [] is used
on the vector itself. So the objects they are used on are different.
Am I correct?
regards,
George
|
|
|
|
|
I have divided one of my Visual Studio projects into "subsystems" using folders to make it easier to navigate between logically seperate subsystems. But my problem is that after a while these folders disappeared. It really annoys me because it takes quite a long time to sort my classes into these folders. Is this a known problem and is there anything I can do to solve the problem?
|
|
|
|
|
The folder information is stored in the project's .opt file, so you'll need to protect if from beeing removed or overwritten. Or, if you're using a version control system, you could have it checked in, checking it out when you make changes to the class tree...
I don't know why they disappear, but it's bothering me as well.
|
|
|
|
|
Thanks that helped i will try and protect that .opt file by moving it into sourcesafe.
|
|
|
|
|
This is no good. This is a VS6 bug, and I had to surrender with it. Now I divide a workspace into subprojects when I want to have my classes separated/grouped.
Regards,
BB
|
|
|
|
|
Hi,
I wanted to use the RTF/CRichEditCtrl as a kind of report system, where the reports are generated from templates of rtf files. Consider a simple application, that needs to fill out a predefined form with some application dependant values.
A first simple solution would be to search and replace Tags within the RTF file with the computed values.
A better solution would be to use the field tag from the RTF specification directly. For example the author field from a word document would look like:
{\field{\*\fldinst
{ AUTHOR \\* MERGEFORMAT }}{\fldrslt {Dirk}}}
where fldinst is the specific field instruction and fldrslt is the latest evaluated result.
Unhappily the CRichEditCtrl does not evaluate internal fields (like author) either, and I couldn't find any Interface in the ITextDocument specification to access the fields of the document.
Does anybody know how to reevaluate the contents of fields programmatically? Something like a callback function with the fied instruction (fldinst) and the return value is the evaluated result? Another possibility would be to reparse the complete document again and aply the evaluated values into the result field (fldrslt) and then feed the document back to the Ctrl.
Any ideas / code?
Thanks
Dirk
|
|
|
|
|
Hi,
does somebody know how to rename an existing project??
Thanks, Mark
|
|
|
|
|
Make a search for vsrename here on CP.
[edit]
Ouuahh connection is fast today, so you will even get a link
Click here[^]
[/edit]
~RaGE();
|
|
|
|
|
Do you realy want to change the project name of just the .exe name? If just the .exe name then (1)select project settings (2)select like tab (3)change the output file name for both debug and release versions (4)change the name(s) in version info. resource and any where else where is might be stored (such as your about box and string table, etc...)
I just did the above today, since the internal project name was not acceptable for a released .exe name.
|
|
|
|
|
Hi.
Got a little question, i need to change the m_pszHelpFilePath member to another value.
Let's assume i have a dialog where i can click english or dutch help file.
If english, m_pszHelpFilePath = appname.HLP
if dutch, m_pszHelpFilePath = appnameD.HLP
(path need to be the path where the exe file is executing)
Does anyone know how to do this?
Greetings
Jens
|
|
|
|
|
Try this (MSDN):
free((void*)m_pszHelpFilePath);
m_pszHelpFilePath=_tcsdup(_T("d:\\somedir\\myhelp.hlp"));
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
yeah i found that too, but how can i know the current directory where the application is running?
And can i access this member everywhere?
|
|
|
|
|
This will give you the current directory where the application is running.
GetModuleFileName ( NULL, strPath, MAX_PATH );
m_pszHelpFilePath is a public member of CWinApp so you can access this member anywhere this way:
AfxGetApp()->m_pszHelpFilePath
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
yeah i've been trying it out:
char path[256];
GetModuleFileName(NULL, path, 256);
CString strFilePath = path;
int idx = strFilePath.ReverseFind( '\\' );
strFilePath.SetAt( idx, '\0' );
AfxMessageBox(strFilePath);
displays "c:\source\myprogram\debug"
free((void*)app->m_pszHelpFilePath);
app->m_pszHelpFilePath=_tcsdup(strFilePath);
it doesn't work .. he still takes the normal path but i think there is a problem with the '\'
i think he has to display "c:\\source\\myprogram\\debug"
Am i right, and so yes how can i easily fix this problem?
...
AfxMessageBox(strFilePath);
strFilePath += "\\MYPROGRAMF.HLP";
AfxMessageBox(strFilePath);
Why doesn't he add "\\MYPROGRAMF.HLP" to the CString????
i totally don't get it anymore
|
|
|
|
|
strFilePath in your program is the path the exe file. If your help file is there two then you don't really need the whole path. strFilePath = "helpfile.hlp". But if you want to proceed with the exe path then you need c:\source\myprogram\debug\helpfile.hlp". In your program all you have is c:\source\myprogram\debug.
Also check CWinApp::WinHelp
char szPath[ MAX_PATH + 1 ];
GetModuleFileName( NULL, szPath, MAX_PATH );
CString strPath = szPath;
int idx = strPath.ReverseFind( '\\' );
length_of_exe_file = 10;
if( idx != -1 )
{
strPath.Delete( idx+1, length_of_exe_file );
}
strPath += "helpfile.hlp";
AfxMessageBox( strPath );
free((void*)AfxGetApp()->m_pszHelpFilePath);
AfxGetApp()->m_pszHelpFilePath=_tcsdup(strPath);
JensB wrote:
it doesn't work .. he still takes the normal path but i think there is a problem with the '\'
i think he has to display "c:\\source\\myprogram\\debug"
\\ is a way for the compiler to read '\'. '\' is called an escape sequence I think. I might be wrong about the name.
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
yes, this is a debug-build
i've put my HLP files compiled alsoo in the debug folder where the .exe file is executing.
But i still have the problem that "helpfile.hlp" is NOT added to the CString .. although AfxMessageBox() doesn't show it well
AfxMessageBox(strPath); //output: c:\myprogram\debug\
strPath += "helpfile.hlp";
AfxMessageBox(strPath);
//output: c:\myprogram\debug\
so "helpfile.hlp" isn't added to the string!?!?
any idea?
|
|
|
|
|
uhm i solved it like this: the file name (standard) was something like 'myproject.HLP' and the other file i changed name to 'myprojectF.HLP' .. and he loads the correct file now
still one question left
-> i wanted to use the member function Insert (CString::Insert(..) but when i compile, the compiles gives an error and says Insert(..) isn't a member of the CString class.
Code (bit messy)
----
CString strCurrPath;
strCurrPath = (CString) (AfxGetApp()->m_pszHelpFilePath);
int idx = strCurrPath.ReverseFind('.');
CString strRechterGedeelte, strLinkerGedeelte,strFull;
strRechterGedeelte = strCurrPath.Right(strlen(strCurrPath)-idx);
strLinkerGedeelte = strCurrPath.Left(strlen(strCurrPath)-strlen(strRechterGedeelte));
strFull = strLinkerGedeelte + "F" + strRechterGedeelte;
free((void*)AfxGetApp()->m_pszHelpFilePath);
AfxGetApp()->m_pszHelpFilePath=_tcsdup(strFull);
|
|
|
|
|
In your source code (in one of your previous postings ) you had something like:
strExePath.SetAt( idx, "\0" );
If you try to add a string to strExePath, you won't be successfull because the string will be added after the null character so you will never be able to se it. That's why I used Delete in the example that I gave you. But anyways, you found your own solution which is very good.
Now going back to your Insert question, I don't see you using it in your source code. How are you using it?
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
yes, i wanted to use the insert member function of CString because then i will be able then to delete three CString variables (strRechterGedeelte, strLinkerGedeelte, strFull) because they are then useless.
This doesn't work:
CString strCurrPath;
strCurrPath = (CString) (AfxGetApp()->m_pszHelpFilePath);
int idx = strCurrPath.ReverseFind('.'); //returns position of '.'
//Now i want to add the char 'F' at that position
int iLength = strCurrPath.Insert(idx, 'F');
AfxMessageBox(strCurrPath);
// error C2039: 'Insert' : is not a member of 'CString'
//!!!!Insert(..) is a member function of CString class
which is alot shorter then (but it works too):
CString strCurrPath;
CString strRechterGedeelte, strLinkerGedeelte,strFull;
strCurrPath = (CString) (AfxGetApp()->m_pszHelpFilePath);
strRechterGedeelte = strCurrPath.Right(strlen(strCurrPath)-idx);
strLinkerGedeelte = strCurrPath.Left(strlen(strCurrPath)-strlen (strRechterGedeelte));
strFull = strLinkerGedeelte + "F" + strRechterGedeelte;
AfxMessageBox(strCurrPath);
and btw, i work with Visual C++ 5
Greetings Jens
|
|
|
|
|
Hi,
I am trying put one rectangle in MemDC and bring to screen.
Here is the code:
CDC MemDC;
CClientDC mydc(this);
MemDC.CreateCompatibleDC(&mydc);
MemDC.Rectagble(&myrect);
MemDC.SelectObject(&mybrush); /////myrect and mybrush I created before
MemDC.FillRect(&myrect,&mybrush);
mydc.BitBlt(0,0,1024,768,&MemDC,0,0,SRCCOPY);
But I am not finding any output.
Help me.
Thanks
Satya
|
|
|
|
|
This can't work...you have to construct a compatible bitmap and select it into the memory DC. At the moment, you are simply drawing on "nothing"...and "nothing" is what you are bitblitting.
greets,
Jason
|
|
|
|