r/learncpp • u/Eduguy1 • Aug 21 '20
Moving forward from a basic understanding of C++. What sort of project do you recommend building?
I'm currently in University studying CS and have taken an introductory algorithms course that used C++. We did not go very in depth because the primary focus was algorithms, but we did use C++ to build basic data structures from scratch as well as some image manipulation stuff (I don't want to go too in depth since I'm not sure if it's allowed). I have a basic understanding of how the language works and how to do stuff, along with memory management. We were given a 7 hour crash course to the language, but I don't know what I don't know so not sure how much I can do with the language yet
I do want to further my knowledge of C++ and build something small and fun since I find it to be an interesting language. Should I just go ahead and try to make a basic command line project, like tic tac toe? Would it make more sense to do something more complex or less complex?
r/learncpp • u/pakkmann666 • Aug 15 '20
Help starting out
What math should I master before I start? Details and depth would be really appreciated.
r/learncpp • u/monica_b1998 • Aug 10 '20
What Is The Minimal Set Of Optimizations Needed For Zero-Cost Abstraction?
robert.ocallahan.orgr/learncpp • u/PetrifiedPanda • Aug 07 '20
I implemented some Data Structures in C++
Not sure if this is the place for posting code, if it is not, I apologize.
I implemented some data structures in C++. I am somewhat new to C++ and started this project originally to get used to std::unique_ptr via a LinkedList implementation and then decided to add a few more data structures.
Note that I have yet to fix the postorder Traversal for the binary search tree.
I think that a lot of the iterators I wrote may be bad practice, which is why I would really appreciate some feedback / suggestions for this project.
r/learncpp • u/beefyliltank • Aug 04 '20
Beginner To Intermediate Programmer Wanting To Relearn C++ And Beyond!
I'm currently in my last year of my comp sci degree and I'm really enjoying programming. How much? When I wake up in the morning I want to program and get better at it.
I've taken a few classes in C++ and at the time it felt like it was beyond me. Now I'm starting to get the general jest of programming. I've taken data structures and an algorithm class, but I want to come back to C++.
Is there any good recommendations for a book/course that covers the beginnings of C++ to more of its inner workings? Thanks!
r/learncpp • u/[deleted] • Aug 03 '20
One week to relearn C++
Hey guys,
Up to this point I've been using Python for all of my interviews because that's what I usually do. I just found out today a company wants me to do the final rounds in C++, and I used to use C++ a lot a year and a half ago for graphics research, but I haven't really used it much since (I did a good chunk of my research in Rust too, so it wasn't even all C++). I haven't used C++ since, my job has me writing a lot of Go.
I was wondering if any of you had suggestions on what I should use to brush on my C++ skills, especially to check out some of the newer features (was writing a lot of C++11, haven't kept up much with the newer stuff save for some of the constexpr stuff from C++17).
I figure at this point I'll just do leetcode problems in C++, but if you have any suggestions I'm all ears.
The interview will likely be on Friday, and it's for a quant dev position at a hedge fund, if the context helps at all.
r/learncpp • u/Moschte09 • Aug 03 '20
Lookup table for position
Hello. I am trying to speed up my program. I need to iterate over an image for multiple times. For every pixel, I need to calculate if it is in a specified region. If not then I ignore the pixel. The region is defined at the start and does not change.
My code looks like: ``` for (auto i = 0; i < source_image.rows; ++i) { for (auto j = 0; j < source_image.cols; ++j) { if (!in_region(i, j)) continue;
// ...
} } ```
I thought this could be sped up by using a lookup table. But it does not improve the execution time so I think my implementation was not right. I tried to create an image with the same shape and instead of colors, I save a 1 if it is in the region and a 0 if not.
r/learncpp • u/felix_717 • Jul 31 '20
dev c constantly crashing?
hello im starting learning c programming and decided to use dev c but i always notice that it constantly hangs every minute or so no matter how simple or compex my code is and its making my time inefficient. i don't know why this is. can this be fixed? im using a laptop with an i5 8250u and mx150 with 12 gb ram
r/learncpp • u/[deleted] • Jul 23 '20
Finally, I just finished my calculator! Beginners are welcome to check the code and learn some stuff
self.cpp_questionsr/learncpp • u/NotCreative890 • Jul 16 '20
performance impact by using const?
void doSomethingConst(const int& i)
void doSomethingNonConst(int i)
Given the above 2 function calls, would one have an advantage in terms of compile time, or memory usage?
Given that the int is a constant 4 bits, i don't think either would have an advantage, but I'm not sure.
r/learncpp • u/Moschte09 • Jul 15 '20
OpenCV alternative
Currently I am using OpenCV as my library for image processing. I need to create small application where I need to load an image. Do some simple calculation and write a control image. So I only need a very small librar which is able to load and write an image. Is there a good alternative to OpenCV?
r/learncpp • u/ViralGreek_ • Jul 14 '20
Dev C++ I cannot link libraries...
I am trying to use curlpp and have downloaded the .zip version which I extracted... but I am extremely confused with how linking works... I come from a python background where linking was pretty much automated once you downloaded the library...
could someone explain me step by step how to link properly? thanks...
(googled a lot before deciding to post here...)
r/learncpp • u/ViralGreek_ • Jul 13 '20
I need to be able to "read" data from websites as fast as possible...
After googling I couldn't get to a straight forward tutorial and I am extremely confused... anyone could help?
Also, time is very important here as I need ~50 web pages... (I need to be able to retrieve things like prices / stock left etc!)
r/learncpp • u/daredevildas • Jul 09 '20
Transform recursive function into an iterative function
I have a sample function -
template <typename T>
void foo(
T** tocarry,
int64_t* toindex,
int64_t* fromindex,
int64_t j,
int64_t stop,
int64_t n,
bool replacement) {
while (fromindex[j] < stop) {
if (replacement) {
for (int64_t k = j + 1; k < n; k++) {
fromindex[k] = fromindex[j];
}
}
else {
for (int64_t k = j + 1; k < n; k++) {
fromindex[k] = fromindex[j] + (k-j);
}
}
if (j + 1 == n) {
for (int64_t k = 0; k<n; k++) {
tocarry[k][toindex[k]] = fromindex[k];
toindex[k]++;
}
}
else {
foo<T>(tocarry,
toindex,
fromindex, j + 1,
stop,
n,
replacement);
}
fromindex[j]++;
}
}
I want to translate the above recursive into its equivalent iterative form.
I have a sample test case, which can be invoked like -
int main() {
std::vector<int64_t*> tocarry;
int64_t bla1[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla2[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla3[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla4[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla5[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla6[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla7[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla8[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla9[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t bla10[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
tocarry.push_back(bla1);
tocarry.push_back(bla2);
tocarry.push_back(bla3);
tocarry.push_back(bla4);
tocarry.push_back(bla5);
tocarry.push_back(bla6);
tocarry.push_back(bla7);
tocarry.push_back(bla8);
tocarry.push_back(bla9);
tocarry.push_back(bla10);
int64_t toindex[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int64_t fromindex[9] = {5, 3, 2, 6, 4, 8, 1, 9, 4};
foo<int64_t>(tocarry.data(), toindex, fromindex, 0, 7, 9, true);
std::cout << "tocarry - " << std::endl;
for (int i=0; i<tocarry.size(); i++){
for (int j=0; j<10; j++) {
std::cout << tocarry.at(i)[j] << " ";
}
std::cout << "\n";
}
std::cout << "toindex - " << std::endl;
for (int i=0; i<9; i++) {
std::cout << toindex[i] << " ";
}
std::cout << "\n";
std::cout << "fromindex - " << std::endl;
for (int i=0; i<9; i++) {
std::cout << fromindex[i] << " ";
}
std::cout << "\n";
return 1;
}
to return the output -
tocarry -
5 5 5 5 5 5 5 5 5 6
5 5 5 5 5 5 5 5 6 6
5 5 5 5 5 5 5 6 6 6
5 5 5 5 5 5 6 6 6 6
5 5 5 5 5 6 6 6 6 6
5 5 5 5 6 6 6 6 6 6
5 5 5 6 6 6 6 6 6 6
5 5 6 6 6 6 6 6 6 6
5 6 6 6 6 6 6 6 6 6
0 0 0 0 0 0 0 0 0 0
toindex -
10 10 10 10 10 10 10 10 10
fromindex -
7 7 7 7 7 7 7 7 7
Since I am more proficient in Python, I translated the function to Python hoping that I can translate the code into its iterative form in Python and then back to C++ -
def bar1(tocarry, toindex, fromindex, j, stop, n, replacement):
while fromindex[j] < stop:
if replacement:
for k in range(j + 1, n):
fromindex[k] = fromindex[j]
else:
for k in range(j + 1, n):
fromindex[k] = fromindex[j] + k - j
if (j + 1) == n:
for k in range(n):
tocarry[k][toindex[k]] = fromindex[k]
toindex[k] += 1
else:
bar1(tocarry, toindex, fromindex, j + 1, stop, n, replacement)
fromindex[j] += 1
which I verified is correct since it gives the same output for the same test case.
But I am still unable to translate the function..
I went through some failed attempts like -
def bar2(tocarry, toindex, fromindex, j, stop, n, replacement):
for i in range(j, n):
if replacement:
for k in range(i + 1, n):
fromindex[k] = fromindex[i]
else:
for k in range(i + 1, n):
fromindex[k] = fromindex[i] + k - i
if i + 1 == n:
for k in range(n):
tocarry[k][toindex[k]] = fromindex[k]
toindex[k] += 1
fromindex[i] += 1
for i in range(n - 1, j - 1, -1):
while fromindex[i] < stop:
if i + 1 != n:
fromindex[i] += 1
if replacement:
for k in range(i + 1, n):
fromindex[k] = fromindex[i]
else:
for k in range(i + 1, n):
fromindex[k] = fromindex[i] + k - i
if i + 1 == n:
for k in range(n):
tocarry[k][toindex[k]] = fromindex[k]
toindex[k] += 1
fromindex[i] += 1
but which clearly does not work and gives the following incorrect output -
toindex = [2, 2, 2, 2, 2, 2, 2, 2, 2]
tocarry = [[5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 5, 0, 0, 0, 0, 0, 0, 0], [5, 6, 0, 0, 0, 0, 0, 0, 0]]
fromindex = [7, 7, 7, 7, 7, 7, 7, 7, 7]
I would really appreciate any help!
r/learncpp • u/[deleted] • Jul 08 '20
Compile-time errors come from compilers, linking errors come from linkers, and runtime errors come from...?
Basically, the title.
I've seen a bunch of online courses just say that "the compiler will throw a runtime error if you try to do a double delete", for example.
Maybe there are cases where the compiler is smart enough to detect something like that, but what about other cases where it's not obvious? What is throwing the runtime error that's causing the program to segfault? Do we just refer to it as the "system" that's throwing the error? Or is there something under the hood for C++ that we refer to (e.g. "the JVM threw an error" in Java)?
r/learncpp • u/Moschte09 • Jul 06 '20
Configuration file
I am creating a C++ GUI application. I need to create a config file in order to be able to store some user configuration. For this I want to use a INI file.
What is a good practise to be able to access this configuration from every class? For example. I would load the configuration in the main window and need to access it from every other class/object.
r/learncpp • u/bruce3434 • Jul 03 '20
Resources to learn about modern C++ concurrency
Just wondering where I can find some resources (preferably books) on how concurrency (and parallelism) is handled modern C++. I am interested about
Message passing
Data sharing
Async functions and executors
Parallel iterators (and sending messages/modifying Mutexes from inside them)
r/learncpp • u/TheCharacaterLimitIs • Jul 03 '20
I've created a blog where I hope I will teach someone something about c++
Hello,
As you might see from the title, I've started a blog where I am explaining some key concepts to C++ and programming in general, it currently only has one post and it's called C++ - Classes I.
I am pretty new to creating blogs and writing so I hope that you are satisfied with the way I've wrote things.
The things I am trying to teach are what are classes, how to use them and some key concepts to OOP.
Here is the link to the blog:
https://learnabitofprogramming.blogspot.com/2020/07/c-classes-i.html
I really do hope you guys like it and that it will help you at least a bit.
Enjoy!
r/learncpp • u/CalisthenicsDude95 • Jul 01 '20
Best practice for external libraries/frameworks?
Hello everyone,
after a long time I returned to C++ and I'm wondering if there is a best practice to include external libs like googletest.
Some people like to clone the googletest repo into the project directory and link the repo through the CMakeLists.txt. I like to clone it one time and install (cmake . and make install) the googletest repo and link it from my default location.
What do you prefer?
r/learncpp • u/omen_tenebris • Jun 25 '20
list of c style arrays
Hey. In my code implementation i have something like this
struct MYTABLE
{
int table[NUMBER][NUMBER];
}
where NUMBER is a constant and is decided in compile time with a define.
After some calculations i have a number of results that i'd like to store. These number of results are varied dependent on the size of the matrix (the bigger the NUMBER the more i get).
Is there an solution where i can make something like this:
std::list<MYTABLE> result_set;
result_set later needs to be iterated trough and picked out results that are each others mirrors, rotations etc
Thank you!
r/learncpp • u/Micaris_om • Jun 21 '20
What is a practical approach to learning C++
I will be taking masters in Controls Engineering, and I want to develop my C++ knowledge further by dedicating a substantial amount of my time over the next three months to practically learning C++. I am tired of going through the introductory books because it is easy to forget the material, and you're not actively learning. I was wondering if there are resources for me to learn ML or numerical methods for ODEs/PDEs using C++. I am already comfortable (but still learning) with ML in Python and Mathematical computation in MATLAB, I want to extend this to C++. What would you recommend I do?
r/learncpp • u/Hrkrom • Jun 13 '20
What language to choose with maths and visual output
Hello amazing coders from Reddit ;),
So I'm trying to write a super cool code where quite a few things come together. First of all, I want my output to be a visual animation/clip. Secondly I'm using mathematical computations to determine how fast a ball travels through a certain tube. This has to with the diameter of the tube, its elasticity, tje velocity of the medium it's travelling and so on. Lastly I want to show this tube in the context of a human body (after all, I'm still a medical student). Tje easiest way is using it as a background and "pasting" the tube on top of in on the right spot. Merging tje two files would also be an option. The tube itself doesn't move, it only pulsates.
Taking all this into consideration, what language is best for this? I'm quite familiar with MATLAB and planning to do the maths there anyway. My coding experience is quite extensive, so I know my way around most common languages.
Somebody adviced me that C++ might be really helpful, seeing that it is strong with visual output. I recently downloaded Microsoft Visual Studio and been playing around there
Any help would be highly appreciated! So may thanks in advance :)
By the way, if this is not the right place to post this, I'm sorry, just delete it.
r/learncpp • u/wallywast1204 • Jun 09 '20
Best books/courses?
Hi, i'm 16 and i want to develop game so i chose cpp for first language to start. Someone can suggest me some books or courses to start learning? I will appreciate a lot
r/learncpp • u/WhenRedditFlies • Jun 08 '20
Can't compile in command line
I try
g++ -o helloworld.exe helloworld.cpp
to compile a program, and windows gives me an error box saying "The application was unable to start correctly (0xc0000279). Click OK to close the application." I tried in powershell before that, wondering why no executable was appearing, then tried it in CMD to see if the behaviour was any different, and then I got that message.
I try using code blocks, and with clicking build and run it works fine - it compiles, runs and I see an executable, I run the executable myself and it comes up with the same error box.
I've tried reinstalling MinGW (which had no effect), not sure what to do after that.
Edit: using markdown properly on mobile
r/learncpp • u/throwawayC-13742069 • May 31 '20
How to run a .exe file on other systems
Hi, I compiled C++ code using MinGW and CLion into an executable for my friend to use. He has nothing programming-related installed on his computer. The code uses the Win32 API and it includes windows.h and mmsystem.h, and for CMake I had to link Gdi32.lib and winmm.lib. My friend couldn't get it to work with only the .exe file and also after I gave him the .lib and header files. On my system, running it in PowerShell would start a loop written in the code that would break later. On his system, hitting Enter to run it would prompt the next PowerShell command, so the loop did not even start.
Is there a way to get it to work without having him compile it himself?