6
frogstair
78d

I'm so angry at c++ I don't even think it's worth a rant

Ugh!

Comments
  • 1
    What did it do?
  • 0
    I feel bad for you.
  • 1
    @RememberMe took my sanity away. Input validation is not working. Docs are unreadable and ununderstandable. All tutorials on "how to get int from cin" totally forget about entering not an int, forums are unhelpful with condescending computer veterans replying with unhelpful shit. I hate c++ with all my heart
  • 0
    @shoop I am a competitive coder and c++ is just the right thing. The template library makes your life hell lot easier.
    If you finding it difficult, start with easy problems and syntax then move on.
  • 1
    @kehsihba well the problem was: get a number from the user, and output a string with correct grammar (Russian). It all worked fine until I started testing 3.5 where there was this weird type casting and it wouldn't compare anything properly and it was just a mess

    Imo that's pretty beginner-level
  • 0
    @shoop When you encounter such problems, just refer to internet. There will be many people who must have got the same error when they have started.
    Anyways, just changed the data type declaration to double.
  • 0
    @shoop are you casting to float and comparing?
    Float comparisons are tricky.
    And if you want input validation, read the input as a string, then check if it's valid, then convert it to int or whatever. An easy way to convert is to use atoi() once you've validated your string (check each char in the string via isdigit maybe).

    The iDiOmAtIc C++ way to convert would be to use stringstream I guess but that's overkill for this.
  • 0
    @RememberMe I guess I could take in a string and convert it, but that's way more cumbersome than just doing a try catch when trying to do atoi, which doesn't work for some reason, or even better, just throw an exception when cannot put what's read into a variable. It's just so clunky
  • 0
    @shoop atoi is a C standard library function, it doesn't use exceptions because C doesn't have them. You can use setjmp+longjmp to implement an exceptions system in C if you want, but that's about it.

    Look at the exceptions (C++) section.
    http://cplusplus.com/reference/...

    Don't expect the C/C++ standard libraries to be like Python's or C#'s. There are a metric ton of legacy things, lots of stuff that were good ideas at the time but kinda pointless now, and lots of seriously good stuff (the STL for example). It's a lot more low level and manual than other languages, which is acceptable because of C/C++'s position in the industry.

    These days you'd use C/C++ only if you want the low level, customisable, stable legacy language type codebase. I suggest you try Python or C# or Java instead if you want a cleaner, more modern and helpful API (though I'll still say that STL is amazing).
Add Comment