|
That all depends on what you are doing. Use char* as little as possible. string is nice when you don't have to worry about multithreaded issues. If you are passing strings between threads, use vector<char> since it isn't reference counted.
For more descriptive details, check out Effective C++ and Effective STL by Scott Meyers.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: since it isn't reference counted.
So how does that solve all the synchronization issues? Depending on the use-model you could create just as many problems using a vector.
led mike
|
|
|
|
|
led mike wrote: So how does that solve all the synchronization issues?
Reference counting is not multithreading-friendly by default Having said that, not all versions aof std::string are reference counted - for instance the Dinkumware one that ships with VC++ is not. Of course, relying on a particular internal implementation is generally a bad idea.
|
|
|
|
|
Nemanja Trifunovic wrote: for instance the Dinkumware one that ships with VC++ is not.
Last time I checked, it was. Link
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
led mike wrote: So how does that solve all the synchronization issues?
It doesn't solve all synchronization issues. STL isn't threadsafe, so you have to use protection around any access to it anyway, but there are issues with passing strings around. I can't remember all the details (and I don't have my copy of Effective STL with me at the moment to look it up) off the top of my head.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: It doesn't solve all synchronization issues.
Ok, sorry my post was probably just stupid.
Zac Howland wrote: I can't remember all the details
This is not simply an oversight; current reference counted implementations may fail for
more complicated examples. They may fail even for s[1] == s[2] if the string s is simultaneously
examined (merely examined, not necessarily modified) by another thread.
SGI Reference[^]
led mike
|
|
|
|
|
|
If you are doing MFC (or want to include the specific headre) then use CString. Otherwise use the string template.
Truth is the subjection of reality to an individuals perception
|
|
|
|
|
How can i access CDialog class from antoher class
that declare in CDialog base application?
best regards,
M.J.M.
|
|
|
|
|
mostafa_pasha wrote: How can i access CDialog class...
Do you mean a CDialog -derived class?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
for example i have CMyFile that is generic class
(my project is CDialog base such as CMyDialog) how
can i access CMyDialog through CMyFile?
is that anyway that call CMyDialog's function from CMyFile
class?
Best regards.
M.J.M.
|
|
|
|
|
CMyFile::Method()
{
CMyDialog dlg;
dlg.DoModal();
}
?
--
Not a substitute for human interaction
|
|
|
|
|
mostafa_pasha wrote: is that anyway that call CMyDialog's function from CMyFile
class?
Sure, but why would you want to? By allowing CMyFile access to the internals of CMyDialog , you have thus tied the two together (i.e., encapsulation). It's especially troublesome if you are wanting CMyFile to manipulate a UI component (e.g., progress bar) that CMyDialog owns. You should be posting a message to CMyDialog instead.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
did you try it?
CMainClass *m_Main=(CMainClass*)GetParent();
m_Main->your variables
|
|
|
|
|
Hi,
it does not work.
GetParent get one argument as HWND.
i change it ,
<br />
CMainClass *m_Main=(CMainClass*)GetParent(theApp.GetMainWnd()->m_hWnd);<br />
but in dialog base application , compiler say " error C2065: 'theApp' : undeclared identifier"
now how can i get pointer to CVerApp class?
CVerApp * = ???;
which function exist to point to my CVerApp?
Best Regards.
M.J.M.
|
|
|
|
|
How to use this file if you use of GetParent(m_hWnd) what happens?
|
|
|
|
|
I have progress bar, i want to change position from
my CMyFile class ! CMyFile class is generic class!
i just want to change position of bar from my CMyFile
so first , i get pointer to my dialog class form CMyFile!
then call function SetPos() of my prograss bar class .
How can i do that?
best regards.
MJM
|
|
|
|
|
if this pointer is valid you dont have problem and you must create this pointer once and again use of it for call your class,I hope it helpful for you but if you have problem you can ask
|
|
|
|
|
Hello all,
I need to find out one of those things for which msdn or other website are almost a useless reference.
I need to check if a file exists in a given folder.
I am sure there is a function that just returns true if the file exists but there is no way I can find it on the web.
Can anyone help?
Ciao
Giulio
|
|
|
|
|
How about the OpenFile() Windows API using the OF_EXIST flag?
Mark
|
|
|
|
|
Giulio2000 wrote: I need to find out one of those things for which msdn or other website are almost a useless reference.
Well, this question certainly is NOT one of those. MSDN, CP, and Google will all give you quick results for this question.
Giulio2000 wrote: I need to check if a file exists in a given folder.
Are you using MFC, Win32 API directly, or standard C++? Depending on which library you want to use, there are several options available to give you this answer. Here is the MSDN link[^] for the MFC way.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I am using MFC.
Thanks for the replies. Trying to open the file with a NO_CREATE option is the obvious solution but it is actually more that I need doing.
There must be a function like IfFileExists(<path to="" file="">) somewhere in MFC but there is no word combination that will give me sensible results on the web.
Ciao
Giulio
|
|
|
|
|
MSDN: Accessing File Status[^]
CFile theFile;
char* szFileName = "c:\\test\\myfile.dat";
BOOL bOpenOK;
CFileStatus status;
if( CFile::GetStatus( szFileName, status ) )
{
bOpenOK = theFile.Open( szFileName,
CFile::modeWrite );
}
else
{
bOpenOK = theFile.Open( szFileName,
CFile::modeCreate | CFile::modeWrite );
}
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
What's wrong with _access(..., 0) , which is just a thin wrapper around GetFileAttributes() ?
You could also use _stat() , which is a wrapper around FindFirstFile() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: What's wrong with _access(..., 0)?
or _stat ?
Unicode?
|
|
|
|