C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

pb avec map et visual c++

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Shaga
Guest





PostPosted: Mon Aug 18, 2003 6:13 pm    Post subject: pb avec map et visual c++ Reply with quote



Bonjour,
voici un petit programme tout con pour voir comment fonctionne map

#include <map>
#include <iostream>

using namespace std;

int main()
{
typedef map< string , int > strint;

strint si;
strint::iterator i;

for(i=si.begin();i<si.end();i++)
{
cout << i->first << " " << i-> second << endl;
}

return 0;
}

J'obtiens 102 erreurs a la compilation et aucune ne reference mon source

c:ateliervc98includefunctional(16) : error C2143: syntax error : missing
'{' before '<'
c:ateliervc98includefunctional(16) : error C2059: syntax error : '<'
c:ateliervc98includefunctional(22) : error C2143: syntax error : missing
'{' before '<'
c:ateliervc98includefunctional(22) : error C2059: syntax error : '<'

Donc ai-je ecris une connerie ou cela vien d'un bug du compilateur (visual
c++ 6 intro) ?

Merci d'avance pour vos reponse.


Back to top
Gabriel Dos Reis
Guest





PostPosted: Mon Aug 18, 2003 6:29 pm    Post subject: Re: pb avec map et visual c++ Reply with quote



"Shaga" <le_shaga (AT) hotemaille (DOT) comme> writes:

Quote:
Bonjour,
voici un petit programme tout con pour voir comment fonctionne map

#include <map
#include
using namespace std;

int main()
{
typedef map< string , int > strint;

strint si;
strint::iterator i;

for(i=si.begin();i<si.end();i++)

un map direct. En particulier la notion de plus petit ou plus grand n'y est
pas défini. La boucle devrait donc s'écrire

for (i = si.begin(); i != si.end(); ++i)
// ...

Ou, si tu veux te la péter,

struct ValuePrinter {
ValuePrinter(std::ostream& os) : out(&os) { }
void operator()(const strint::value_type& v) const
{
*out << v.first << " " << v.second << endl;
}

private:
std::ostream* out;
};

std::for_each(si.begin(), si.end(), ValuePrinter(std::cout));

-- Gaby

Back to top
Shaga
Guest





PostPosted: Mon Aug 18, 2003 6:37 pm    Post subject: Re: pb avec map et visual c++ Reply with quote



Merci beaucoup

"Gabriel Dos Reis" <gdr (AT) integrable-solutions (DOT) net> a écrit dans le message de
news: [email]m3isoues51.fsf (AT) uniton (DOT) integrable-solutions.net[/email]...
Quote:
"Shaga" <le_shaga (AT) hotemaille (DOT) comme> writes:

| Bonjour,
| voici un petit programme tout con pour voir comment fonctionne map
|
| #include <map
| #include |
| using namespace std;
|
| int main()
| {
| typedef map< string , int > strint;
|
| strint si;
| strint::iterator i;
|
| for(i=si.begin();i<si.end();i++)

un map direct. En particulier la notion de plus petit ou plus grand n'y est
pas défini. La boucle devrait donc s'écrire

for (i = si.begin(); i != si.end(); ++i)
// ...

Ou, si tu veux te la péter,

struct ValuePrinter {
ValuePrinter(std::ostream& os) : out(&os) { }
void operator()(const strint::value_type& v) const
{
*out << v.first << " " << v.second << endl;
}

private:
std::ostream* out;
};

std::for_each(si.begin(), si.end(), ValuePrinter(std::cout));

-- Gaby



Back to top
Luc Hermitte
Guest





PostPosted: Tue Aug 19, 2003 9:52 pm    Post subject: Re: pb avec map et visual c++ Reply with quote

Bonsoir.

Gabriel Dos Reis <gdr (AT) integrable-solutions (DOT) net> wrote in
news:m3isoues51.fsf (AT) uniton (DOT) integrable-solutions.net:

Quote:
struct ValuePrinter {
ValuePrinter(std::ostream& os) : out(&os) { }
void operator()(const strint::value_type& v) const
{
*out << v.first << " " << v.second << endl;
}

private:
std::ostream* out;
};

Question idiote. Pourquoi un pointeur et pas une référence (pour le flux)
?

Juste parce que rouge, ou alors il y a raison cachée à cette approche ?

--
Luc Hermitte FAQ de <news:fr.comp.lang.c++> :
<http://www.cmla.ens-cachan.fr/Utilisateurs/dosreis/C++/FAQ/>
Dejanews : <http://groups.google.com/advanced_group_search>

Back to top
Gabriel Dos Reis
Guest





PostPosted: Wed Aug 20, 2003 4:10 pm    Post subject: Re: pb avec map et visual c++ Reply with quote

Fabien LE LEZ <gramster (AT) gramster (DOT) com> writes:

Quote:
On 20 Aug 2003 14:53:17 +0200, Gabriel Dos Reis
[email]gdr (AT) integrable-solutions (DOT) net[/email]> wrote:

Content-Type: multipart/mixed; boundary="=-=-="

Toujours des problèmes avec ton lecteur de news ?

je suis pourtant certain lui avoir dit de n'en envoyer les messages
qu'en un seul charset.

-- Gaby

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.