Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Hmm? It looks like the C++ I've had to do in classes, seems pretty textbook-standard
-
@billgates I think it's probably just an early example to show how to use nested ifs. Most textbooks have that in the first couple of chapters.
-
donuts238487yNow they introduced auto....
auto a = 1; fine...
but auto sum(int x, int y)
why would you ever use auto for a function declaration?
Is C++ turning into JS? -
b3b343777yWhy are you using "using namespace std"? Not that cats will die or anything but it can be dangerous using it. I always write std::cout or std::string
-
@billgates you're not writing 'std::string', I guess that's his point. Indirectly you're using the namespace Std by this.
Personal flavor I guess, as long as one does not run into problems. 😃 -
donuts238487y@Emphiliis I used typedef string std::string?
Isn't that just like an alias? bc I don't want to type std all the time? -
b3b343777y@billgates yeah by using "using namespace std;" you wont have to type std all the time. But why the heck did you typdef string? Never seen that before 😂😂
-
AlexAC53757y@billgates if the grade is lower than 70 you don't need to make another 2 ifs, this is a bit faster, probably not significantly but this way it can make you to think before writing slow code
-
@AlexAC35 Indeed. If this was looping through thousands of grades you could avoid a lot of unnecessary ifs since we can expect that only a few will be in the 80-100 area.
-
donuts238487y@b3b3 because they went over typedef in chapter 1...
Also I'm a C# Java guy... std::string just feels strange...
Why did they even call the namespace std.... Every single time I read it I think of STDs.... -
@endor \n > std::endl
@billgates instead of writing
typedef std::string string;
You could've just written
using std::string; -
donuts238487y@Krokoklemme will I have the type def in a header file and then just include it in all the cpp files.
Would using work as well? -
endor57517y@Krokoklemme endl flushes the buffer, \n doesn't.
Personally, unless I have that specific need, I stick with endl, to avoid any unexpected weird behaviour (and because when I tell my program to print stuff, I want it there and then) -
@endor that's just partially true. stdout is newline-buffered, which means that it'll get flushed every time it encounters a newline
@billgates yes, 'using' would work too (and is actually preferred, as it's the "C++ way") -
donuts238487y@Krokoklemme but not cin?
I think I had to use cin.ignore so the outer function wouldn't also get the value -
-
donuts238487y@Krokoklemme but when I have a shell script written in Windows... I need to convert the EOL characters to Linux ones or else it won't run?
-
@billgates that's really just a matter of displaying stuff. Windows can handle "raw" newlines just as good as Linux does.
-
donuts238487y@Krokoklemme nope... If the sh file isn't Linux EOL formatted, shell will complain.
http://bencane.com/2014/02/... -
@billgates errrmmm... I know, I was talking about that Windows EOL doesn't necessarily have to be \r\n
-
donuts238487y@Krokoklemme I thought we were talking about how endl is the same as \n and \n will work for any system.
But there is a diff though in endl depending on OS? -
@billgates \n and endl differ in that way, that endl guarantees the stream it's applied upon to be flushed and yes: \n does work for every system (AFAIK at least)
But idk if there are any differences in endl depending on the platform
OMFG... Should I continue reading this book on C++....
rant
that is some ugly code...