oh snap...this is starting to get crazy for me...
what do i do about the 95 warnings?
also since my map has integer and a vector of strings, i must also define an iterator for the vector of my strings in my map object?
simple class and vector question.
hello, basically now, i am experimenting with the map class. when i compile i get a bunch of warnings. maybe vc++ is not up to date? well at least i am not getting any error.
in the map class iterator, if my iterator is pointing to something, it seems that i have access to first and second fields? thats pretty cool. i am just wondering if/when i create my map<int, vector <string>>, how will i insert new items into my map, and new strings to the string vector?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
//#include "history.h"
using namespace std;
int main()
{
//typedef vector<string> history;
map<int,string> myHistory;
map<int,string>::iterator pos;
myHistory.insert(map<int, string>::value_type(5,"hello"));
myHistory.insert(map<int, string>::value_type(6,"77.33"));
myHistory.insert(map<int, string>::value_type(7,"hellothere"));
pos = myHistory.begin();
cout << " size = " << myHistory.size() << endl;
for (pos = myHistory.begin(); pos != myHistory.end(); ++pos)
{
if (pos->first == 6)
{
cout<< "found it" << endl;
}
}
pos = myHistory.find(5);
cout<< "pos = " << pos->first << endl;
return 0;
}
in the map class iterator, if my iterator is pointing to something, it seems that i have access to first and second fields? thats pretty cool. i am just wondering if/when i create my map<int, vector <string>>, how will i insert new items into my map, and new strings to the string vector?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
//#include "history.h"
using namespace std;
int main()
{
//typedef vector<string> history;
map<int,string> myHistory;
map<int,string>::iterator pos;
myHistory.insert(map<int, string>::value_type(5,"hello"));
myHistory.insert(map<int, string>::value_type(6,"77.33"));
myHistory.insert(map<int, string>::value_type(7,"hellothere"));
pos = myHistory.begin();
cout << " size = " << myHistory.size() << endl;
for (pos = myHistory.begin(); pos != myHistory.end(); ++pos)
{
if (pos->first == 6)
{
cout<< "found it" << endl;
}
}
pos = myHistory.find(5);
cout<< "pos = " << pos->first << endl;
return 0;
}
Quote:Original post by rip-offWhilst I would still suggest putting in the space (for portability), MS actually made VS2005 smart enough to work without the space, i.e. >> doesn't get parsed as right shift within template declarations.
C++ compilers will reject that.
C++ compilers parse >> as the right shift operator, even inside template declarations.
(Yeah I was shocked too![smile])
Quote:Original post by iMalcQuote:Original post by rip-offWhilst I would still suggest putting in the space (for portability), MS actually made VS2005 smart enough to work without the space, i.e. >> doesn't get parsed as right shift within template declarations.
C++ compilers will reject that.
C++ compilers parse >> as the right shift operator, even inside template declarations.
(Yeah I was shocked too![smile])
I wouldn't call it smart, because it fail to treat it as a shift operator when you want a shift operator.
#include <iostream>using namespace std;template<int T> struct foo{ int bar() const {return T;}};int main(){ foo< 4>>1 > baz; // baz is of type foo<2> cout << baz.bar() << endl; return 0;}
Not a common situation maybe, but still, it fails while, as far as I know, it shouldn't. g++ 3.4 on FreeBSD compiles it just fine.
In other words, they fixed one thing and broke another.
Quote:Original post by baker
i am just wondering if/when i create my map<int, vector <string> >, how will i insert new items into my map, and new strings to the string vector?
Some examples how to use are given in the manual i posted before:
http://www.sgi.com/tech/stl/Map.html
int main(){ map<const char*, int, ltstr> months; months["january"] = 31; months["february"] = 28; months["march"] = 31;... cout << "june -> " << months["june"] << endl;}
Also using typedefs would make things easier to read.
Next thing is your declare:
map<int,string> myHistory;
This means that map<int,string>::key_type is int and map<int,string>::value_type is string.
Then you call
myHistory.insert(map<int, string>::value_type(5,"hello"));
You should better use:
myHistory[5] = "hello";
hi, thanks again for the reply. i took a look at the example and they show something very similiar to the C++ book i am looking at.
i see how the map is int and string, but is it possible to have an array of strings or a vector of strings? if its a vector of strings, how can i access the vector or strings through the map and add and delete?
i see how the map is int and string, but is it possible to have an array of strings or a vector of strings? if its a vector of strings, how can i access the vector or strings through the map and add and delete?
Quote:Original post by Brother BobOh so they did![rolleyes]
I wouldn't call it smart, because it fail to treat it as a shift operator when you want a shift operator.
*** Source Snippet Removed ***
Not a common situation maybe, but still, it fails while, as far as I know, it shouldn't. g++ 3.4 on FreeBSD compiles it just fine.
In other words, they fixed one thing and broke another.
I wasn't convinced that it was a good move on their part anyway. But breaking code that should be valid is teh suxors.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement