Membres inscrits :2359
Membres en ligne : 0
Invités en ligne : 1


|
Conversation (Résolue) : Vector string syntaxe |
Ded (Membre)
Lieu: Grenoble (38)
Inscrit le : 09-09-2013
Messages: 41
Snippets: 0
Tutoriels: 0
Hors ligne |
Bonjour, J'ai un problème pour compiler ce fragment :
Code Cpp: #include <iostream> #include <vector> using namespace std; vector<string> find_all(string& s, char c) { vector<string> res; for (auto p = s.begin(); p!=s.end(); ++p) if(*p==c) res.push_back(s); return res; } int main() { cout << "Hello world!" << endl << endl; string m {"Mary has a little lamb"}; char c = 'c'; for (auto p : find_all(m,c)) if(*p!=c) cout << "letter " << c << " bug" << endl; return 0; }
Code: -------------- Build: Release in iterator (compiler: GNU GCC Compiler)--------------- mingw32-g++.exe -Wall -fexceptions -O2 -std=c++11 -ID:\CPP\id3lib\id3lib-3.8.3\include -c D:\CPP2\iterator\main.cpp -o obj\Release\main.o D:\CPP2\iterator\main.cpp: In function 'int main()': D:\CPP2\iterator\main.cpp:22:13: error: no match for 'operator*' in '*p' Process terminated with status 1 (0 minute(s), 0 second(s)) 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) Merci pour toute aide.
|
Code::Blocks 13.12 on Windows 7 (build 7601 service pack 1 64 bit edition). GNU GCC version 4.7.1 -std=c++11 Make version 3.82. wxWidgets 3.0.0 compiled shared=0 monolithic=1 unicode=1 build=release.
|
Xaviou (Administrateur)
Lieu: Annecy (74)
Inscrit le : 27-08-2007
Messages: 1390
Snippets: 25
Tutoriels: 6
Site web
Hors ligne |
Salut.
À la ligne 22, 'p' est en fait un 'string'. Donc, '*p' ne veut rien dire...
@+ Xav'
|
Le nouveau portail wxWidgets francophone : www.wxdev.fr Ben en fait, vous y êtes déjà ... et effectivement, depuis le temps, ce n'est plus tellement nouveau....
|
|