This question already has answers here:
Speed and stability of libraries 'stdio' vs. 'iostream' [closed]
(4 answers)
Closed 7 years ago.
So I'm at university second semester and we are learning Data Structures. Back in first semester we used to learn C, and now we are moving on C++ (I guess due to the OOP, which allows us to implement those data structures).
But apparently we are still including C's libraries instead of C++'s. I'm aware that stdio is for C and iostream is for C++. I'm wondering why use stdio instead of iostream? is cout << bad/slow/etc?
It's because your "professor" is used to it, and is teaching obsolete/antiquated techniques.
It won't do you much good in the real world.
This is even more apparent by your use of the name "iostream.h" — this suggests you're being taught on Turbo C++ using a DOS emulator, as if it's still 1991. It's not still 1991. In real C++ it's just "iostream".
The world moved on some twenty years ago.
Well done for asking, though. So so so so so so so so many don't. :(
Related
This question already has answers here:
Is there a C++ equivalent to getcwd?
(8 answers)
Closed 2 years ago.
I'am familiar that getcwd() function is available in c to get current working directory.Is there a std function in cpp for the same?
Yes.
C++17 has std::filesystem::current_path.
On a POSIX system, you can also just keep using getcwd(). getcwd() is not actually part of C. Even it were, you could still keep using it, as the C Standard Library is available in C++; however, you've probably heard that it is preferable to use the C++ Standard Library where possible, and that's largely true.
Use current_path() method in boost::filesystem or std::filesystem::current_path() in c++17
I'm sorry about asking a weird question about this. I googled and looked up to here for a solution, but none of the answers satisfy what actually I want.
I am really confused about this question. It's been almost 2 years that I have been studying for security based work. So, I have good knowledge about Python and C.
The company that I referred gave me advise to learn about Win32. But when I begin to learn about it, I encountered that Win32 is C++ based. But I don't want to waste time again to study it. Some blogs talk about Windows Programming in C/C++, and this makes more confusion for me as C and C++ are essentially separate from each other, I think.
My questions are:
Can I learn Win32 with only C?
If no, then can I learn it over C?
If yes, how deep do I have to go (so, all context of it or specific)?
So again sorry. I'm really very confused at the moment that I don't know what I have to do.
As far as I know - yes, it should be possible. The older Windows APIs were in fact C based and that's what I learned myself 20 years ago. They're quite straightforward. The newer ones are based on COM which is a bit more of a hassle to do in C, but by no means impossible. I remember reading some good tuorials on doing just that (COM in C), although I don't have any handy links to give out I'm afraid.
That said, C and C++ are quite close. In fact, C++ was originally intended to be a superset of C - every valid C program was supposed to be a valid C++ program. Now, they didn't quite make that happen, but the differences are subtle and for the most part shouldn't bother you much. So you might as well continue writing code in C, using just a bit of C++ for interfacing with COM. The C++ compiler should accept this just fine.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
In school I was taught C++ using Turbo C++ 7 . When I entered college , I found out that it was out dated . I would like to know the changes which have been implemented in C++ 14 in GCC or Dev C++ compiler.
Example : conio.h does not exist in C++98, C++14 etc. instead we have using namespace std; .
Notice that <conio.h> does not exist in any programming language standard. You could check with the C11 draft standard on n1570. You could check with the C++14 standard too (and you could check with all earlier standards of C or of C++). FWIW, I'm coding since the 1970s and never used <conio.h>
I'm using a good, very standard conforming, implementation of C11 and of C+14 and it has no <conio.h>. My computer runs Linux and my compiler is GCC 7.
The <conio.h> header is specific to MicroSoft systems. AFAIK no standard mentions it. You won't find <conio.h> on POSIX (and all non-MicroSoft) systems (you should prefer ncurses for POSIX, it is a free software library commonly used). Even 1990s era Unix workstations did not have
<conio.h> and current non-Microsoft systems don't have them.
TurboC++ is an obsolete compiler. It compiled an obsolete, never standardized, variant of a subset of C++. Don't use TurboC++ today!
BTW, DevC++ (or Code::Blocks) are not compilers, but IDEs. They are running some (configurable) compiler, often GCC.
I strongly recommend using some recent free software C++ compiler, notably GCC or Clang/LLVM. Both are very standard conforming (with some tiny documented deviations).
Don't forget to enable all warnings and debug info (most compilers don't enable them by default). With GCC compile with g++ -Wall -Wextra -g.
I even very strongly recommend installing some Linux distribution on your computer, because they are very developer friendly and made of free software whose source code you can study.
If you want to learn C++, be sure to learn and use at least C++11 (and preferably C++14, which is very close to C++11). Any older standard is not worth learning (unless your employer forces you to) in 2017.
Of course, a C++ compiler alone is not enough (BTW nearly all of them are command line programs). You also need other tools, notably linkers and loaders and assemblers (e.g. binutils); you need some source code editor (my preference is GNU emacs but you could use vim or gedit or many others) - some of them call themselves IDEs - and you want to use a debugger (such as GNU gdb), a version control system (I recommend git), a build automation tool (like GNU make).
Most Linux distributions are packaging all that very nicely.
Once you have read a good introduction to C++ programming, take the habit to look on cppreference. Be aware that C++ is a very complex programming language (and few people know it very well, I don't claim to know it well and probably never met any person knowing it very well), so prepare yourself to spend several years learning it. An important notion is that of undefined behavior.
BTW, the most important differences between the language accepted by TurboC and the C++14 standard are not syntactic, but semantics.
From what you say (and reference to conio.h), the most likely conclusion is that you were not taught C++ (using Turbo C++ 7). You were taught "C with some C++ features sprinkled over". What some ambiguously call "C/C++". That's what most learn in good high schools, and it can serve you well through coding competitions.
So follow these steps:
accept that you don't know C++ (or that "what you know is not real C++")
go over the introductory "A Tour of C++" from Bjarne Stroustrup, the guy who created C++, and fill in the gaps between "what you know" and "modern C++"
read a bit about the differences between the language features of various C++ standard versions (start by google-ing "C++14 features" etc.)
pick a good C++ book, like maybe "Effective C++" (or others, ask around a bit!) and go through it alongside your courses in the first few years of college
Tip: Somewhere between 3 and 4, when you'll realize it's going to take you years and years to master C++, stop and ask yourself "is C++ the right language for the kinds of programs I want to write?". If the answer is "no", pick something else. If the answer is "yes", then pause and take some detours: a couple detours to the "underworlds" of assembler and "real plain C" (the type you find in Linux's kernel), and a couple detours to the "alternative universes" of D, Rust and Go, to understand what's wrong with C++ and why it's responsible for most of the world's bugs and security holes (hint: there's a lot wrong!), and how to mitigate its anti-features.
Oh, and... don't despair :)
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
The Definitive C++ Book Guide and List
Learning C++ Language
Hello I am just starting to learn C++, does anyone have any suggestions for C++ learning resources, for example books and web sites. In addition, does anyone have any suggestions for IDEs?
Many years ago I used Bruce Eckel's books - they were not a 100% perfect but they explained things well. And probably the best thing about them now is they are available online for free. http://www.ibiblio.org/pub/docs/books/eckel/
Are you familiar with any other programming language (like C etc)?
if you are, you should straight away start to get your hands dirty. no use investing more time reading. You can learn more by doing. All you need is to search for "c++ hello world" in google, I do it whenever I want to code in any language.
Websites:
http://www.cplusplus.com/doc/tutorial/
http://www.learncpp.com/
IDE:
I am not sure if you need an IDE. Visual Studio is the only IDE I have seen being used for C++ in industry. Eclipse has plugins for all popular languages.
Since you are just learning the language (I am assuming you are using Windows), I would suggested DevCpp.
Other tools:
If Windows: notepad++
If Linux: gedit & g++
Pitfalls:
learning C++ or java doesnt automatically make you good at object oriented programming (OOP). So please try to learn OOP concepts and apply them in these languages.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C Analog To STL
Is there something like STL for C.
You can have a look at the glib, which provides lots of interesting features
well there is the C library of course :) but I do not see the use of templates for C
There's not really anything quite like the STL; but there are a lot of libraries. glib has been mentioned, but usually it's not always useable together with whatever libraries you are using for actually achieving what you want to do.