What does “missing template argument” mean?

I’m pretty new to C++ and this site so there are bound to be errors. When I try to compile my code I get errors like error: missing template argument before ‘b’. I’ve been searching the world for answers for hours and it has led me here. My assignment is to implement a templated class Collection …

Read more

Compiling a C++ program with gcc

gcc can actually compile c++ code just fine. The errors you received are linker errors, not compiler errors. Odds are that if you change the compilation line to be this: which makes it link to the standard c++ library, then it will work just fine. However, you should just make your life easier and use g++. EDIT: …

Read more

Static array vs. dynamic array in C++

Local arrays are created on the stack, and have automatic storage duration — you don’t need to manually manage memory, but they get destroyed when the function they’re in ends. They necessarily have a fixed size: Arrays created with operator new[] have dynamic storage duration and are stored on the heap (technically the “free store”). They can …

Read more

Division in C++

In the expression 1 / 6, both numbers are integers. This means that this division will perform integer division, which results in 0. To do a double division, one number has to be a double: 1.0 / 6 for example.

std::out_of_range error?

I’m dealing with a file with a linked list of lines with each node looking like this: and I’m writing a function that adds spaces at the beginning of the lines found in the variable text, by calling functions like linelist_ptr->text.insert(0,1,’\t’); The program compiles, but when I run it I get this error: Any ideas?

What is the difference between std::atoi() and std::stoi?

1). Are there any other differences between the two? I find std::atoi() a horrible function: It returns zero on error. If you consider zero as a valid input, then you cannot tell whether there was an error during the conversion or the input was zero. That’s just bad. See for example How do I tell if the c …

Read more