-
June 29th, 2010, 09:29 AM
#1
[MFC] problems usings cstring
Dear All,
I am trying to get hold of cstring and hash tables using C++ MFC. This article (http://en.wikipedia.org/wiki/Hash_map_(C%2B%2B)) inspired me and I tried to do the follow:
Code:
#pragma once
#include <cstring>
// CUConversionTable command target
class CUConversionTable : public CObject
{
public:
CUConversionTable();
CUConversionTable(CStdioFile& tableFile, CString category);
~CUConversionTable();
private:
//by default the size is set to 10
double m_inputFactors[10];
double m_outputFactors[10];
std::string m_symbolTable[10];
int m_nSymbols; //nr of elements in the conversion table
};
Unfortunately there are some compilation errors. Keeping std::string the following happens:
Code:
1>u:\mydocs\visual studio 2008\projects\multipeviewtest\multipeviewtest\uconversiontable.h(16) : error C2039: 'string' : is not a member of 'std'
Could amone suggest me what I am doing wrongly..
many thanks and Best Regards,
oengCC
Last edited by pengCC; June 29th, 2010 at 09:31 AM.
-
June 29th, 2010, 09:34 AM
#2
Re: [MFC] problems usings cstring
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
June 29th, 2010, 10:05 AM
#3
Re: [MFC] problems usings cstring
Many thanks for that..
any experience using hash_map? I I tried the following:
Code:
// This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface
// (the "Fluent UI") and is provided only as referential material to supplement the
// Microsoft Foundation Classes Reference and related electronic documentation
// included with the MFC C++ library software.
// License terms to copy, use or distribute the Fluent UI are available separately.
// To learn more about our Fluent UI licensing program, please visit
// http://msdn.microsoft.com/officeui.
//
// Copyright (C) Microsoft Corporation
// All rights reserved.
// MultipeViewTestView.cpp : implementation of the CMultipeViewTestView class
//
#include "stdafx.h"
#include "MultipeViewTest.h"
#include "MultipeViewTestDoc.h"
#include "MultipeViewTestView.h"
#include "UConversionTable.h"
#include "UConversion.h"
#include <iostream>
#include <hash_map>
#include <string>
using namespace std;
//using namespace __gnu_cxx;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMultipeViewTestView
IMPLEMENT_DYNCREATE(CMultipeViewTestView, CFormView)
BEGIN_MESSAGE_MAP(CMultipeViewTestView, CFormView)
ON_BN_CLICKED(ID_GB1, &CMultipeViewTestView::OnBnClickedGb1)
ON_WM_SETFOCUS()
ON_BN_CLICKED(IDC_CONVERSIONTABLEREAD, &CMultipeViewTestView::OnBnClickedConversiontableread)
ON_BN_CLICKED(IDC_CMAPTEST_BUTTON, &CMultipeViewTestView::OnBnClickedCmaptestButton)
ON_BN_CLICKED(IDC_BUTTON2, &CMultipeViewTestView::OnBnClickedButton2)
END_MESSAGE_MAP()
struct eqstr{
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1,s2)==0;
}
};
Code:
void CMultipeViewTestView::OnBnClickedCmaptestButton()
{
//classic
hash_map<const char*, int, hash<const char*>, eqstr> months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
}
void CMultipeViewTestView::OnBnClickedButton2()
{
AfxMessageBox(L"Generate table");
CUConversionTable myTable;
// TODO: Add your control notification handler code here
}
The error message is:
1>u:\mydocs\visual studio 2008\projects\multipeviewtest\multipeviewtest\multipeviewtestview.cpp(182) : error C2065: 'hash_map' : undeclared identifier
Many thanks and Best Regards,
pengCC
-
June 29th, 2010, 10:17 AM
#4
Re: [MFC] problems usings cstring
I actually found the last question in the FAQ.. http://www.codeguru.com/forum/showthread.php?t=315286
But why does VC++ has to be always different than C++? Could they not just make a compiler that recognizes "classic" C++ language as Apple did with the iPhone SDK?
-
June 29th, 2010, 10:27 AM
#5
Re: [MFC] problems usings cstring
There's nothing 'classic' about hash_map, as it's never been part of the C++ standard. Every STL library writer tended to come up with their own version.
VS supports the official version of hash_map
It's called std::tr1::unordered_map
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
June 29th, 2010, 11:02 AM
#6
Re: [MFC] problems usings cstring
Note that VS2008 or better is required for TR1's unordered_map. I think it's been aliased up to the std namespace as well in VS2010.
-
June 30th, 2010, 02:58 AM
#7
Re: [MFC] problems usings cstring
Thanks for the clarification..
I am trying to understand whether I should use CMap or hash_map.. the project I am working on is pretty big and has a complex GUI written in MFC.. we will have a backend doing computations and we will be exploiting the Document/View architecture massively.
In a sense I'd like to use hash_map for portability (in case the company will need to reuse the code in a close or far future using another language). But CMap probably is a winner having an entirely MFC project..
what are ur thoughts on this dilemma? What are the criteria u use when choosing which datatype u are using>
Many thanks and Best Regards,
pengCC
-
June 30th, 2010, 03:41 AM
#8
Re: [MFC] problems usings cstring
I wonder how are going to "reuse the code" that is "pretty big and has a complex GUI written in MFC"... ""in a close or far future using another language"?
It just means that you will have to completely overwrite the whole code!
So at this position you may forget about any "portability ... using another language"!
Victor Nijegorodov
-
July 1st, 2010, 03:25 AM
#9
Re: [MFC] problems usings cstring
I am developing also a version of the software for some mobile devices and would be ideal that good part of the logic code (conversion, computation etc..) gets coded in C++ as most of the mobile SDK compilers (even iPhone) supports C++. Coding using MFC classes presents some advantages like when using serialization.. but yeah, those not as big as saving the time of recoding all the non-GUI part..
Last edited by pengCC; July 1st, 2010 at 05:15 AM.
Reason: edited grammar error
-
February 9th, 2022, 07:17 AM
#10
Re: [MFC] problems usings cstring
I think it's very dangerous to use different library (like cstring) in big projects without rescue management..devs from IT Craft (my current company) talks about software project rescue ...
Last edited by VictorN; February 9th, 2022 at 08:03 AM.
Reason: Web link was removed.
-
February 9th, 2022, 07:19 AM
#11
Re: [MFC] problems usings cstring
and pls welcome to discuss it
-
February 9th, 2022, 08:05 AM
#12
Re: [MFC] problems usings cstring
Originally Posted by voronkovl99
and pls welcome to discuss it
OK! Just begin the discussion, but, please, start a new thread and don't spam with the links to your "current company"!
Victor Nijegorodov
-
February 9th, 2022, 08:35 AM
#13
Re: [MFC] problems usings cstring
Originally Posted by VictorN
OK! Just begin the discussion, but, please, start a new thread and don't spam with the links to your "current company"!
but it's not spam!
what is "spam" in your mind?
-
February 9th, 2022, 09:45 AM
#14
Re: [MFC] problems usings cstring
It is just what you posted!
If you'd like to discuss about using different libraries then just start the discussion!
If instead you'll go on with discussion about "spam or non-spam", then you will be banned.
Note hat this Forum is:
Forum: Visual C++ Programming
Ask questions about Windows programming with Visual C++ and help others by answering their questions.
Victor Nijegorodov
-
February 9th, 2022, 12:12 PM
#15
Re: [MFC] problems usings cstring
References to IT Craft could be taken as advertising - which isn't allowed.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|