Click here to Skip to main content
15,892,674 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: sorting charater array alphabetically Pin
Joaquín M López Muñoz19-May-05 3:17
Joaquín M López Muñoz19-May-05 3:17 
GeneralRe: sorting charater array alphabetically Pin
BlackDice19-May-05 5:39
BlackDice19-May-05 5:39 
Questionmulti-monitors? Pin
Anonymous19-May-05 3:05
Anonymous19-May-05 3:05 
AnswerRe: multi-monitors? Pin
Blake Miller19-May-05 5:13
Blake Miller19-May-05 5:13 
GeneralThread - Process synchronization Pin
javi_jmc19-May-05 2:47
javi_jmc19-May-05 2:47 
GeneralRe: Thread - Process synchronization Pin
Alexander M.,19-May-05 4:19
Alexander M.,19-May-05 4:19 
GeneralRe: Thread - Process synchronization Pin
Blake Miller19-May-05 5:22
Blake Miller19-May-05 5:22 
GeneralProblems with std::map Pin
ChemmieBro19-May-05 2:31
ChemmieBro19-May-05 2:31 
This is my first experience with maps and I am having some troubles.
I have developed a Logger that can do private logs depending on the client who calls the COM object. Based on the client's information, it needs to find the specific file to log to.

Here is my code:
//(header declarations)
std::map<BSTR, ofstream*> m_FileList;
std::map<BSTR, ofstream*>::iterator mFileListIterator;

//(code)
bool ClientHasCalledBefore;
_bstr_t FileName; //name of the file coming in.

//Look for FileName in map to see if it was called before.
ClientHasCalledBefore = (!(m_FileList.find(FileName) == m_FileList.end()));

// If it has called before, it logs to a clear file.
// If not, it creates the file, then appends the logs.
if (!ClientHasCalledBefore)
{
ofstream *ofstr = new ofstream(FileName, ios::out);
m_FileList[FileName] = ofstr;
*m_FileList[FileName] << "EntryToBeLogged";
m_FileList[FileName]->close();
}
else
{
m_FileList[FileName]->open(FileName, ios::app);
*m_FileList[FileName] << "EntryToBeLogged";
m_FileList[FileName]->close();
}


Okay. This code leads me to my first question. When I enter a new file into the map, sometimes it does not enter properly and the next time the conditional is checked, the FileName is not found. It does this sometimes the first one to three times it runs through. After the first couple of times, everything works fine. Because I am opening the file clean, this overwrites the first couple of entries. Any suggestions so that my conditional finds the entry in the map the first time?

//**************
In my destructor, I have this code to add a footer to every file:

for (m_FileListIterator = m_FileList.begin(); m_FileListIterator != m_FileList.end(); ++m_FileListIterator)
{
(m_FileListIterator->second)->open(FileListIterator->first, ios::app);
*(m_FileListIterator->second) << "FooterToBeAdded";
(m_FileListIterator->second)->close();
}

I think something is totally flawed with this. Sometimes it will append to a file I would have never created in my code, making a new file. Other times it will log the footer into the same file multiple times. It is almost as if it is not iterating.

Again, this is my first experience with any of this. Any help is much appreciated. Thank you.
GeneralRe: Problems with std::map Pin
Joaquín M López Muñoz19-May-05 3:08
Joaquín M López Muñoz19-May-05 3:08 
GeneralRe: Problems with std::map Pin
ChemmieBro19-May-05 3:27
ChemmieBro19-May-05 3:27 
GeneralRe: Problems with std::map Pin
Joaquín M López Muñoz19-May-05 3:34
Joaquín M López Muñoz19-May-05 3:34 
GeneralRe: Problems with std::map Pin
ChemmieBro19-May-05 4:13
ChemmieBro19-May-05 4:13 
Generalvirtual inheritance Pin
SimpleProgramer19-May-05 2:27
SimpleProgramer19-May-05 2:27 
GeneralRe: virtual inheritance Pin
Joaquín M López Muñoz19-May-05 2:56
Joaquín M López Muñoz19-May-05 2:56 
Questionhow to copy and paste a nonregular area of an image Pin
Anonymous19-May-05 1:19
Anonymous19-May-05 1:19 
AnswerRe: how to copy and paste a nonregular area of an image Pin
Chris Losinger19-May-05 3:50
professionalChris Losinger19-May-05 3:50 
Generalfile type associations Pin
gx4419-May-05 0:58
gx4419-May-05 0:58 
GeneralRe: file type associations Pin
Joel Holdsworth19-May-05 1:11
Joel Holdsworth19-May-05 1:11 
QuestionCross Network communication using Winsock2? Pin
arrya_amit19-May-05 0:39
arrya_amit19-May-05 0:39 
AnswerRe: Cross Network communication using Winsock2? Pin
ThatsAlok19-May-05 1:44
ThatsAlok19-May-05 1:44 
Generalsimple installer Pin
dave2k19-May-05 0:16
dave2k19-May-05 0:16 
GeneralRe: simple installer Pin
Jack Puppy19-May-05 0:19
Jack Puppy19-May-05 0:19 
GeneralDAO and ADO in same project Pin
MK7818-May-05 22:47
MK7818-May-05 22:47 
GeneralRe: DAO and ADO in same project Pin
RChin18-May-05 23:49
RChin18-May-05 23:49 
GeneralRe: DAO and ADO in same project Pin
MK7818-May-05 23:59
MK7818-May-05 23:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.