Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Unable to run an example program.
Qt 6.11 is out! See what's new in the release blog

Unable to run an example program.

Scheduled Pinned Locked Moved Unsolved C++ Gurus
8 Posts 4 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sylas
    wrote on last edited by
    #1

    I am a beginner. I tried little numbers (between 1 and 6. I tried names. I tried telephone numbers. No success. Maybe a second file is missing. Can somebody help me. Thanks a lot. Here is tje file :
    // example illustrating the use of std::list.

    // This is not an example of good style, just an illustration of facilities

    // pp 54-55, sec 3.7.3

    // No guarantees offered. Constructive comments to bs@research.att.com

    #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;

    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");
    

    }

    ? 1 Reply Last reply
    0
    • S Sylas

      I am a beginner. I tried little numbers (between 1 and 6. I tried names. I tried telephone numbers. No success. Maybe a second file is missing. Can somebody help me. Thanks a lot. Here is tje file :
      // example illustrating the use of std::list.

      // This is not an example of good style, just an illustration of facilities

      // pp 54-55, sec 3.7.3

      // No guarantees offered. Constructive comments to bs@research.att.com

      #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;

      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");
      

      }

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @Sylas Hi! What is t you're trying to accomplish with your code? What do you want to do?

      S 1 Reply Last reply
      0
      • ? A Former User

        @Sylas Hi! What is t you're trying to accomplish with your code? What do you want to do?

        S Offline
        S Offline
        Sylas
        wrote on last edited by
        #3

        @Wieland Hi !
        I am a beginner. I tried little numbers (between 1 and 6. I tried names. I tried telephone numbers. No success. Maybe a second file is missing. Can somebody help me. Thanks a lot. Here is tje file :
        // example illustrating the use of std::list.

        // This is not an example of good style, just an illustration of facilities

        // pp 54-55, sec 3.7.3

        // No guarantees offered. Constructive comments to bs@research.att.com

        #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;

        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");
        

        }
        That is what the console shows. What shal I do for running that ?? Many thanks.

        K 1 Reply Last reply
        0
        • S Sylas

          @Wieland Hi !
          I am a beginner. I tried little numbers (between 1 and 6. I tried names. I tried telephone numbers. No success. Maybe a second file is missing. Can somebody help me. Thanks a lot. Here is tje file :
          // example illustrating the use of std::list.

          // This is not an example of good style, just an illustration of facilities

          // pp 54-55, sec 3.7.3

          // No guarantees offered. Constructive comments to bs@research.att.com

          #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;

          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");
          

          }
          That is what the console shows. What shal I do for running that ?? Many thanks.

          K Offline
          K Offline
          KeithS
          wrote on last edited by
          #4

          @Sylas said:

          That is what the console shows. What shal I do for running that ??

          What does the console show? What errors are you seeing?

          btw, I can't see what this has to do with Qt?

          S 1 Reply Last reply
          0
          • K KeithS

            @Sylas said:

            That is what the console shows. What shal I do for running that ??

            What does the console show? What errors are you seeing?

            btw, I can't see what this has to do with Qt?

            S Offline
            S Offline
            Sylas
            wrote on last edited by
            #5

            @KeithS Sorry . I made a mistake.
            {one 1}
            {two 2}
            {three 3}
            and so on (about 6 more lines) . I tried a copy-paste of my console without success.

            K 1 Reply Last reply
            0
            • S Sylas

              @KeithS Sorry . I made a mistake.
              {one 1}
              {two 2}
              {three 3}
              and so on (about 6 more lines) . I tried a copy-paste of my console without success.

              K Offline
              K Offline
              KeithS
              wrote on last edited by
              #6

              @Sylas

              So what's the error? Is there any error?

              S 1 Reply Last reply
              0
              • K KeithS

                @Sylas

                So what's the error? Is there any error?

                S Offline
                S Offline
                Sylas
                wrote on last edited by
                #7

                @KeithS Thanks. No there is no error at all; I suppose it's a Stroustrup product. But i dont know what to do for making it run.

                1 Reply Last reply
                0
                • jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You could use debugger

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved