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. Mac Stringstream returns wrong output
QtWS25 Last Chance

Mac Stringstream returns wrong output

Scheduled Pinned Locked Moved Unsolved C++ Gurus
c++qtcreator 4.9.1stringstreammac os
32 Posts 8 Posters 7.6k Views
  • 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.
  • F fcarney
    31 May 2019, 21:34

    @Bugi said in Mac Stringstream returns wrong output:

    I don't think there are many opportunities to change the compiler on macOS.

    I think Python is the same way on MacOS.

    Can you add an independent compiler? One that you can run from the command line? Not one that changes the entire system compiler. My Linux system has a standard gcc compiler installed, but I can install clang and it won't mess up everything else. That would at least give you a way to do your school work.

    I still think the VM option with Linux on it may be your best option. I know you don't want to, but it will give you a lot more options. It will also give you experience in Linux if you don't already have that.

    B Offline
    B Offline
    Bugi
    wrote on 31 May 2019, 21:49 last edited by
    #23

    @fcarney
    Agree and have begun to take baby steps with linux (ubunto).
    I was dedcated windows user some years ago (before windows 8) and have worked on windows machines afterwards continued.
    regarding my school work i have found a windows machine for the moment.
    BUT. I am still detement to make it work on mac os. I'm really tired of hearing people say you can't be an engineer with a mac.

    and I'm really happy with my mac :(
    And although I have a windows machine it doesn't help the others in my class with the same problem (mac user)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcarney
      wrote on 31 May 2019, 21:57 last edited by
      #24

      @Bugi said in Mac Stringstream returns wrong output:

      I'm really tired of hearing people say you can't be an engineer with a mac.

      The guy I share an office with is an electrical engineer (30+ years), he is a good programmer, uses a Mac, but runs most of his analysis software and programming tools on a VM running Windows 10. I run Linux and use a VM to run Windows 10 for doing Windows development in Qt. Most of my time is in Linux though. So, there is nothing wrong with a Mac. However, no matter what you run, you will probably need a VM to run something else. Or your boss will make a decision that forces you to run a VM. Its just how it goes.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • B Bugi
        31 May 2019, 21:34

        @kshegunov

        Okay maybe we found something here ...
        but since I still have very little code experience I don't know if it is something or not... Or for that matter what it means
        Output:

        ios_base::clear: unspecified iostream_category error
        libc++abi.dylib: terminating with uncaught exception of type std::__1::ios_base::failure: ios_base::clear: unspecified iostream_category error
        Press <RETURN> to close this window...
        

        It went directly to line 49: (throw) after line 39: (ss >> coeff;)
        Se folder and Debug_4 for code and images.

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 1 Jun 2019, 11:23 last edited by
        #25

        @Bugi said in Mac Stringstream returns wrong output:

        Okay maybe we found something here ...
        but since I still have very little code experience I don't know if it is something or not... Or for that matter what it means

        It means one of two things:

        1. You're reading past the end of stream.
        2. You're reading formatted input (the >> operators), which is not formatted according to the expectation; i.e. there's something wrong while reading from the stream.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        3
        • K Offline
          K Offline
          Kent-Dorfman
          wrote on 2 Jun 2019, 00:42 last edited by
          #26

          just for grins...please replace std:stringtream with std::istringstream and retest. Since you are only using the stream for input, you should use the istream specialization intended for that purpose.

          1 Reply Last reply
          0
          • B Bugi
            31 May 2019, 21:34

            @kshegunov

            Okay maybe we found something here ...
            but since I still have very little code experience I don't know if it is something or not... Or for that matter what it means
            Output:

            ios_base::clear: unspecified iostream_category error
            libc++abi.dylib: terminating with uncaught exception of type std::__1::ios_base::failure: ios_base::clear: unspecified iostream_category error
            Press <RETURN> to close this window...
            

            It went directly to line 49: (throw) after line 39: (ss >> coeff;)
            Se folder and Debug_4 for code and images.

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 2 Jun 2019, 01:56 last edited by JKSH 6 Feb 2019, 08:42
            #27

            @Bugi said in Mac Stringstream returns wrong output:

            ios_base::clear: unspecified iostream_category error
            libc++abi.dylib: terminating with uncaught exception of type std::__1::ios_base::failure: ios_base::clear: unspecified iostream_category error
            

            Someone found a bug in clang's stringstream exception detection before (http://clang-developers.42468.n3.nabble.com/libc-ios-base-and-exceptions-td4038960.html ); it's quite possible that your compiler has a buggy implementation of stringstream. This would explain why everyone on this forum was unable to reproduce your issue, yet all 6 macOS users in your class have the same issue.

            Unless you have a way to try a different compiler on your macOS, you'll have a hard time proving or disproving that the bug is in your compiler.

            Does this exercise require you to use stringstream? If not, try a different way of parsing the string.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            J K 2 Replies Last reply 2 Jun 2019, 02:08
            3
            • J JKSH
              2 Jun 2019, 01:56

              @Bugi said in Mac Stringstream returns wrong output:

              ios_base::clear: unspecified iostream_category error
              libc++abi.dylib: terminating with uncaught exception of type std::__1::ios_base::failure: ios_base::clear: unspecified iostream_category error
              

              Someone found a bug in clang's stringstream exception detection before (http://clang-developers.42468.n3.nabble.com/libc-ios-base-and-exceptions-td4038960.html ); it's quite possible that your compiler has a buggy implementation of stringstream. This would explain why everyone on this forum was unable to reproduce your issue, yet all 6 macOS users in your class have the same issue.

              Unless you have a way to try a different compiler on your macOS, you'll have a hard time proving or disproving that the bug is in your compiler.

              Does this exercise require you to use stringstream? If not, try a different way of parsing the string.

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 2 Jun 2019, 02:08 last edited by JKSH 6 Mar 2019, 03:17
              #28

              Anyway, in situations like this, it is useful to create minimal test cases to investigate the issue.

              int main() {
                  std::string pstr = "22x^3+2x^2-1x^0";
                  std::stringstream ss(pstr);
              
                  double coeff = -42.0;
                  ss >> coeff;
                  std::cout << coeff << std::endl;
              }
              

              What does this print for you? If it's the wrong value, what happens if you replace pstr with "22"?

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              3
              • J JKSH
                2 Jun 2019, 01:56

                @Bugi said in Mac Stringstream returns wrong output:

                ios_base::clear: unspecified iostream_category error
                libc++abi.dylib: terminating with uncaught exception of type std::__1::ios_base::failure: ios_base::clear: unspecified iostream_category error
                

                Someone found a bug in clang's stringstream exception detection before (http://clang-developers.42468.n3.nabble.com/libc-ios-base-and-exceptions-td4038960.html ); it's quite possible that your compiler has a buggy implementation of stringstream. This would explain why everyone on this forum was unable to reproduce your issue, yet all 6 macOS users in your class have the same issue.

                Unless you have a way to try a different compiler on your macOS, you'll have a hard time proving or disproving that the bug is in your compiler.

                Does this exercise require you to use stringstream? If not, try a different way of parsing the string.

                K Offline
                K Offline
                Konstantin Tokarev
                wrote on 2 Jun 2019, 19:35 last edited by
                #29

                @JKSH said in Mac Stringstream returns wrong output:

                Unless you have a way to try a different compiler on your macOS, you'll have a hard time proving or disproving that the bug is in your compiler.

                However, it would be wise to update Xcode to the latest available version before investigating further

                1 Reply Last reply
                2
                • B Bugi
                  29 May 2019, 08:12

                  Hi we are two students in my class who has a slightly strange experience with string stream on our Qt installation C++

                  Common trails of setup:

                  • macOS Majave v. 10.14
                  • Qt Creator 4.9.1
                  • Kit: Desktop Qt 5.12.2 clang 64bit (default)

                  Our Code C++: main.cpp

                  /#include <iostream>
                  #include <sstream>
                  #include <vector>
                  #include <utility>
                  
                  std::vector<std::pair<double, int> > readPolynomial(std::string& p);
                  
                  int main() {
                      std::string pstr = "22x^3+2x^2-1x^0";
                      std::vector<std::pair<double, int> > poly = readPolynomial(pstr);
                  
                      for (unsigned int i = 0; i < poly.size(); ++i) {
                          if (i>0) {
                              if (poly[i].first > 0) {
                                  std::cout << "+";
                              }
                          }
                          std::cout << poly[i].first << "x^" << poly[i].second;
                      }
                      std::cout << std::endl;
                  
                      return 0;
                  }
                  
                  std::vector<std::pair<double, int> > readPolynomial(std::string& p) {
                      std::vector<std::pair<double, int> > poly(3);
                      std::stringstream stringstream(p);
                  
                      for (size_t i{0}; i < 3; i++) {
                          stringstream >>  poly[i].first;
                          stringstream.ignore(2);
                          stringstream >>  poly[i].second;
                      }
                  
                      return poly;
                  }
                  

                  Output: Terminal

                  0x^00x^00x^0
                  

                  Any suggestions?
                  PS. please be detailed we are first year and new to Qt, C ++, and Terminal command

                  Update 1:
                  Im not he best at using the debugging tool.
                  but at the following link you can fine some pictures of the debugging window.
                  link debugging Images

                  B Offline
                  B Offline
                  Bugi
                  wrote on 3 Jun 2019, 08:14 last edited by
                  #30

                  @Bugi

                  I have some exams the next 2 weeks. so the problem is paused :( i will be back and thanks for the help until now

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    wraitii
                    wrote on 16 Jun 2019, 09:32 last edited by wraitii
                    #31

                    I've ran in the same problem in 0 A.D. (see here).

                    Edit: this is in fact a difference between libstd and libc and it has been reported before: https://bugs.llvm.org/show_bug.cgi?id=17782

                    K 1 Reply Last reply 16 Jun 2019, 10:05
                    4
                    • W wraitii
                      16 Jun 2019, 09:32

                      I've ran in the same problem in 0 A.D. (see here).

                      Edit: this is in fact a difference between libstd and libc and it has been reported before: https://bugs.llvm.org/show_bug.cgi?id=17782

                      K Offline
                      K Offline
                      Konstantin Tokarev
                      wrote on 16 Jun 2019, 10:05 last edited by Konstantin Tokarev
                      #32

                      @wraitii Thanks for information! You've probably meant libstdc++ and libc++, because libc is kinda different thing

                      1 Reply Last reply
                      1

                      • Login

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