What are some good uses for C++?

closed account (9wk3b7Xj)
I'm 16 years old, and in June I jumped into programming. I'd say I'm average in both C++ and Python, although whenever I need to automate something or I come up with an idea I always go to Python. Python makes network programming easier for me, and things like iptables where I just really can't find an efficient way of doing it in C++. I haven't read as many Python books as C++, I'm currently on my second C++ book. However, I can never find any applications for C++. I've done things like write my own String class, but I haven't actually tackled any projects of my own. I don't know if it's just a lack of creativity on my part, or something else. What are some good usss for C++ that I might be able to create projects with?
So you want to run C when you want something extremely fast, with low overhead, and very customizable like a operating system.
Basically you can do everything with C++.
However it doesn't mean you should use it for everything.
C++ is a good - maybe the best - choice for writing an OS, compiler, graphic libraries...
Many things are easier with other languages like GUI programming, web sites, network programming
If you don't have ideas it's probably a lack of creativity - why do you want to program at all then?
Programming is about solving problems, if you don't have problems....
> What are some good uses for C++ that I might be able to create projects with?

This list may give you an idea about what kinds of programs could be written using C++:
http://www.stroustrup.com/applications.html
closed account (9wk3b7Xj)
"Programming is about solving problems, if you don't have problems...."

Where did I imply that I don't want to program? I've come up with several small ideas, but they've always been more suitable in Python - such as a script that automatically blacklists malicious IPs trying to bruteforce SSH/SFTP logins, and a program that tells me what my schedule is at school. Ironically, I love C++ more than Python because it's such a large and powerful language. I enjoyed Bjarne Stroustrup's exercises in Programming Principles and Practices Using C++, but I've finished the book already.
You misunderstood Thomas1965's comment.
C++ is a tool that you use to solve problems. Taking C++ and looking for problems to solve with it is akin to buying a hammer and looking for things to hit with it.

Your Python examples showcase the right way to go about it. You had a problem and you looked for a suitable tool to solve it with. I would agree that Python was probably a better tool for the job than C++ in those specific situations. Python lends itself well to quick solutions where you only need to call to other existing code, without doing much processing in Python itself. "Glue code", as it's called.
Comparatively, C++ works better in more complex projects, where most of the time will be spent executing the code *you* write. C++ also has facilities that encourage more robust code, such as static typing and deterministic resource management. Static typing is also better suited for projects with multiple developers: in Python you have to know how to call a function in order to use it, and if someone else wrote that function they had better documented it, and if you make a mistake the language will never tell you until that call is executed. Meanwhile, in C++ type correctness is enforced always (unless you explicitly override it), and this allows you to specify part of a function's contract directly in the code. At the very least, you know that you'll never accidentally pass a string to a function expecting a list of numbers.

Other cases where C++ works well:
* When you need tighter control of resource usage, specifically CPU time and memory.
* When you need to interface with C code and you don't want to use C. One reason you might not want to use C is that it's usually easier to write correct C++ code than correct C code.
* When you want to write portable code. For example, at the moment the best way to write code that can run mostly unmodified in both Android and iOS is using either C or C++. Although C generally has better support in "weird" platforms, such as microcontrollers, or for kernel development (e.g. Linux drivers).
Thomas1965 wrote:
Many things are easier with other languages like GUI programming, web sites, network programming
This is true for the entry level. Once you overcome that you will usually appreciate the plus of freedom c++ offers.

chiltz6401 wrote:
they've always been more suitable in Python - such as a script that automatically blacklists malicious IPs trying to bruteforce SSH/SFTP logins, and a program that tells me what my schedule is at school.
There is nothing wrong with using other languages that suits better in certain situations.

closed account (9wk3b7Xj)
@helios
Thank you for the detailed and explanatory reply. I just want to improve my use of C++, although I'm having trouble finding good exercises. I've already done things like binary conversion, quizzes from files, etc.
Well, your question was about "uses", not "exercises". There's no such thing as a bad exercise, there's just some that are too easy or too hard for a given skill level.
If you just want exercises there's hundreds to choose from. Here's one:

Write a calculator that evaluates expressions of the form 1 + (-3 * 5)^6. Remember that
1 + 2 * 3 = 6 7
2 * 3^4 = 162
2^3^2 = 512
Last edited on
closed account (9wk3b7Xj)
I know that C is a very low level language, although it seems like C++ just uses the same libraries as C for this stuff -- but would C++ be good for creating Linux stuff? I know some daemons are written in C.
C is a high level language, just like C++.

but would C++ be good for creating Linux stuff?
I guess that depends on what you mean by "stuff".
Anything that resides entirely in user mode, including daemons, can be made in C++. A daemon is just a normal process that runs in the background and provides some service to other processes, after all.
For things in kernel mode, such as drivers and kernel modules, that a different story. I don't know much about Linux kernel development, but my understanding is that writing drivers and kernel modules in C++ is not supported. Here's a relevant post on the subject: https://www.threatstack.com/blog/c-in-the-linux-kernel/
To be frank, none of that sounds particularly daunting to me.
C++ is a general-purpose programming language. It can be used for anything.

Having said that, in keeping with its ideology, there are things it doesn't support directly. For example:
1) It doesn't provide a library for a GUI.
2) It doesn't provide a library for RDBMS interfaces.

For these 2 requirements (which are essential in the Business Application software domain, and also probably required in other domains as well), we have other options:

1) To still use C++, we need to use 3rd-party libraries for the above purposes.
2) Avoid C++ and use another language altogether.

I should note that, given object-orientation, learning a new language isn't a trifle, any more. Apart from the core language features, we need to acquire proficiency in myriad libraries.

For platform-portability, C++ and Java are suitable, though C++ is likely to be much faster, since it is fully compiled, whereas Java is JIT-compiled (just-in-time).
Remember that
1 + 2 * 3 = 6


I think @helios meant
1 + 2 * 3 = 7
.

I believe his point is that order of operations says that the answer is not 9.
Heh heh. Whoops.
Topic archived. No new replies allowed.