Le mardi 24 mai 2016 08:24:44 UTC+2, aubertin.sylvain a écrit :
> The mame of this code is "list". It seems to be incomplete (nowhere a cin instruction). It runs but it doesn't work. May any one help me (I am a beginner).
> Here is the code:
>         
> /*phone_book.cpp*/
> 
> #include<list>                                                           
> #include<iostream>
> #include<string>
> using namespace std;
> 
> struct Entry {
>         string name;
>         int number;
>         Entry(const string& n, int i) :name(n), number(i) { }
> };
>                                                                        
> list<Entry> phone_book;
> 
> void print_entries()
> /*
>         this kind of function should use a parameter,        
>         rather then a global name
> */
> {
>         typedef list<Entry>::const_iterator LI;
> 
>         for (LI i = phone_book.begin(); i != phone_book.end(); ++i) {
>                 const Entry& e = *i;    // reference used as shorthand
>                         cout << '{' << e.name << ' ' << e.number << "}\n";
>         }               
> }
> 
> void print_entry(const string& s)
> /*
>         Is this the right treatment of a string not found?
> */
> {
>         typedef list<Entry>::const_iterator LI;
> //                                                                        13/               
>         for (LI i = phone_book.begin(); i != phone_book.end(); ++i) {
>                 const Entry& e = *i;    // reference used as shorthand
>                 if (s == e.name) {
>                         cout << e.name << ' ' << e.number << '\n';
>                         return;
>                 }
>         }
> }
> 
> void f(const Entry& e, list<Entry>::iterator i, list<Entry>::iterator p)
> /*
>         just some nonsense code
> */
> {
>         phone_book.push_front(e);       // add at beginning
>         phone_book.push_back(e);        // add at end
>         phone_book.insert(i,e);         // add before the element referred to by `i'
> 
>         phone_book.erase(p);            // remove the element referred to by `p'
> }
> 
> int main()
> {
> 
>         phone_book.push_back(Entry("one",1));                        
>         phone_book.push_back(Entry("two",2));
>         phone_book.push_back(Entry("three",3));
>         phone_book.push_back(Entry("four",4));
>         phone_book.push_back(Entry("five",5));
>         Entry six("six",6);
>         print_entries();
>         f(six,phone_book.begin(),phone_book.begin());
>         print_entries();
>         print_entry("four");
>         print_entry("seven");
>         print_entry("three");
> }                                                                        
> Thanks again
Hi Dominique. I tried to do something with the result of the object file, without any success. I should like to have your opinion: is it possible with a new function (2 cin inside) to make this program complete ??
 I tried many times, but the compiler returns me a lot of errors. Thanks again.
-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
--- 
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment