Mac Stringstream returns wrong output
-
Be sure the stream's not corrupted:
std::stringstream ss(p); ss.exceptions(std::stringstream::failbit | std::stringstream::badbit); try { for (size_t i = 0 ;i < 3; i++) { ss >> coeff; ss.ignore(2); ss >> power; poly.push_back(std::make_pair(coeff,power)); } } catch (const std::exception & e) { std::cerr << e.what() << std::endl; throw; }
You'd need the appropriate headers too:
#include <exception> #include <iostream>
-
I don't think there are many opportunities to change the compiler on macOS. Since the installation settings come with XCode. Actually tried "this" before I started this thread. and had to format my entire pc and reinstall everything.
I treed to type " $ gcc --version " to answer you question. and don't know whether this is useful...
MY-MacBook-Air:~ bugi$ gcc --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.1 (clang-1001.0.46.4) Target: x86_64-apple-darwin18.6.0 Thread model: posix InstalledDir: Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
I fund this .pro file in the project folder
TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt SOURCES += \ main.cpp HEADERS +=
I tried reinstalling the latest Qt Open Source version:
Under the instalion setup there is a step where you are installing components: where i have 2 options at this step.
1. is to install as. Qt 5.12.3 -> macOS :
This installation resultet in nothing working at all!
couldn't even compile with the auto-detected kit. Or correct it to something that worked.
So I uninstalled it again (Both time with the MaintenanceTool which removed all files from the system).
I then tried again this time with the other option under installing component.
2. which is to install as. Qt 5.12.2 -> macOS : I was then able to compile my projects again but it made no difference. It is still "0x^00x^00x^0" as output.I alså tried 3.th, 4.th, and a 5.th time.
3.th time with both option 1. and 2. simultaneously. this resultere in that nothing would compile. again with the auto-kit or any setting (qmake return 2)
The 4.th and 5.th time both time by uninstalling both Qt and XCode. And agin it was only possible to make the qt installation with component: Qt 5.12.2 -> macOS. able to compile any of my projects. still with the wrong output. "0x^00x^00x^0" -
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. -
@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.
-
@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) -
@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.
-
@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 meansIt means one of two things:
- You're reading past the end of stream.
- 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.
-
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.
-
@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.
-
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"?
-
@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