Click here to Skip to main content
15,891,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Difference between visual c++ and visual c++.net Pin
David Crow8-Sep-05 7:29
David Crow8-Sep-05 7:29 
AnswerRe: Difference between visual c++ and visual c++.net Pin
Christian Graus8-Sep-05 12:27
protectorChristian Graus8-Sep-05 12:27 
GeneralRe: Difference between visual c++ and visual c++.net Pin
Ming Luo8-Sep-05 21:45
Ming Luo8-Sep-05 21:45 
GeneralRe: Difference between visual c++ and visual c++.net Pin
Christian Graus11-Sep-05 11:15
protectorChristian Graus11-Sep-05 11:15 
QuestionMS Hierarchical FlexGrid Pin
pjhenry12168-Sep-05 5:31
pjhenry12168-Sep-05 5:31 
Questionhow to accessing std:map (index)th element Pin
yccheok8-Sep-05 4:42
yccheok8-Sep-05 4:42 
AnswerRe: how to accessing std:map (index)th element Pin
Maximilien8-Sep-05 5:54
Maximilien8-Sep-05 5:54 
GeneralRe: how to accessing std:map (index)th element Pin
garbash8-Sep-05 7:06
garbash8-Sep-05 7:06 
You can but there could be a high price to pay performance-wise depending our the std::map implementation you are using:

#include <map>
#include <string>
#include <iostream>
void main( )
{
typedef std::map<int, std::string> Numbers;
Numbers n;
n.insert(Numbers::value_type(1,"one"));
n.insert(Numbers::value_type(2,"two"));
n.insert(Numbers::value_type(3,"three"));

Numbers::iterator iCurrent = n.begin();
// You can use the 0-based index of the element to access
// This is not an efficient way to access element of map
// and there is no out-of-boundary validation. You have
// been warned!
std::advance(iCurrent, 1);

std::cout << (iCurrent->second).c_str() << std::endl;
}

A better approach would probably be to store your data in a std::vector, the sort it with std::sort. This way you can use std::find to achieve logarithmic access time as per std::map or instant access time with std::vector's operator[].

Good luck,

g.
AnswerRe: how to accessing std:map (index)th element Pin
Bob Stanneveld8-Sep-05 10:42
Bob Stanneveld8-Sep-05 10:42 
QuestionEdit a record in a DB table opened with ODBC Pin
sirtimid8-Sep-05 4:32
sirtimid8-Sep-05 4:32 
AnswerRe: Edit a record in a DB table opened with ODBC Pin
David Crow8-Sep-05 4:35
David Crow8-Sep-05 4:35 
GeneralRe: Edit a record in a DB table opened with ODBC Pin
sirtimid8-Sep-05 4:51
sirtimid8-Sep-05 4:51 
GeneralRe: Edit a record in a DB table opened with ODBC Pin
David Crow8-Sep-05 5:53
David Crow8-Sep-05 5:53 
QuestionRedefinition Pin
Babto8-Sep-05 4:13
Babto8-Sep-05 4:13 
AnswerRe: Redefinition Pin
Cedric Moonen8-Sep-05 4:17
Cedric Moonen8-Sep-05 4:17 
GeneralRe: Redefinition Pin
Babto8-Sep-05 5:41
Babto8-Sep-05 5:41 
GeneralRe: Redefinition Pin
Maximilien8-Sep-05 5:59
Maximilien8-Sep-05 5:59 
AnswerRe: Redefinition Pin
David Crow8-Sep-05 4:32
David Crow8-Sep-05 4:32 
QuestionProblem with worker thread Pin
ashtwin8-Sep-05 4:06
ashtwin8-Sep-05 4:06 
AnswerRe: Problem with worker thread Pin
David Crow8-Sep-05 4:34
David Crow8-Sep-05 4:34 
AnswerRe: Problem with worker thread Pin
Marc Soleda8-Sep-05 4:37
Marc Soleda8-Sep-05 4:37 
AnswerRe: Problem with worker thread Pin
Jim Howard8-Sep-05 12:54
Jim Howard8-Sep-05 12:54 
AnswerRe: Problem with worker thread Pin
ThatsAlok8-Sep-05 18:16
ThatsAlok8-Sep-05 18:16 
QuestionEdit a record in a DB table opened with ODBC Pin
sirtimid8-Sep-05 3:52
sirtimid8-Sep-05 3:52 
AnswerRe: Edit a record in a DB table opened with ODBC Pin
David Crow8-Sep-05 6:01
David Crow8-Sep-05 6:01 

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.