Posts by Ossetian_Odin • 331 points
16 posts
-
1
votes2
answers3232
viewsA: Assign one class to another in C++
I don’t understand the purpose/logic of your code. I think what you want to do is called "downcasting", which is only possible through pointers and references: #include <iostream> using…
-
2
votes1
answer574
viewsA: How to check if the value of a key exists on a map in c++
Just use the method find of std::map. This will return an iterator if the iterator is not equal to the iterator end() from your map, so that means the key value exists. Example: #include…
-
1
votes3
answers1589
viewsA: How to read file line . txt from index 0
Another solution(if I understood the problem well) would be you use regular Expressions: #include <string> #include <iostream> #include <regex> using namespace std; int main() {…
-
1
votes1
answer865
viewsA: Python to C++ conversion
I think there is no simple way to implement this in C++. Certain languages like Python can only be expressed in C++ with hacks or complicated logics. But you could do so: #include <iostream>…
-
1
votes2
answers261
viewsA: I connect to the database but the values do not change when I give UPDATE MYSQL Qt C++
Instead of concatenating the query string, try something like this: #include <QVariant> ... ... QSqlQuery query query.prepare("UPDATE matricula SET NmAluno= ?, NmCurso= ?, NmEscola=? WHERE…
-
0
votes1
answer393
viewsA: Copying strings in C
First of all, in C you always need additional space in your array because the strings need a null character (which can be represented with 0 or '\0') to indicate where they end up. And to copy a…
-
2
votes2
answers2428
viewsA: How to use getche() with do-while in C?
To read a character, just use scanf even. char ch; scanf(" %c", &ch); printf("%c", ch); Note that in the scanf has a space %c. This serves to indicate that the function ignores all additional…
-
1
votes1
answer361
viewsA: system() does not accept string type variable in c++
The function system is not a function originating from C++ but from the C language, so it receives const char* and not std::string. The C++ string is nothing more than an array of C characters…
-
0
votes1
answer136
viewsA: C++ Time Management System
1 - In the "addAtivity" method, you forgot to use "( )" in the part where you call the function that returns the size of the vector. The right is "activities.size()" or the compiler will understand…
c++answered Ossetian_Odin 331 -
1
votes1
answer215
viewsA: Parallel programming Qt C++
From what I understand, your code tries to do the calculation within a certain time frame, so I think it’s normal for the position to vary. About the wrong result (the number not being prime), I…
-
4
votes1
answer62
viewsA: Can c++ templates only be used once?
The error occurs because the compiler does not see the type T in the second function. Two functions cannot share the same generic type, you need to declare each function as template:…
c++answered Ossetian_Odin 331 -
1
votes1
answer104
viewsA: C++: Vector in a function
First of all, you cannot use "sizeof" to check the amount of string in a standard array, because the string class uses pointers and dynamic allocation internally. You will have to pass the size of…
-
0
votes1
answer339
viewsA: Read and save information (C++)
First, you forgot the string header: #include <string> Second, the problem is that "getline" only accepts strings. You first need to convert numerical values. If you are using a C++11/14…
c++answered Ossetian_Odin 331 -
0
votes1
answer196
viewsA: Problems opening c++ software on another PC
There is a program called Dependency Walker, that can analyze the dependencies of an executable file. Try opening your program with it and then play all the DLL files it indicates in the same folder…
-
3
votes2
answers198
viewsA: Pointer changes the value within function in C++
The accounts in your functions are wrong. You should use +, -, *, / instead of +=, -=, *= and /=. And I believe the error happens when the program tries to read the character of the operation. The…
-
0
votes1
answer68
viewsA: Problem executing methods of a generic class
I think the error is in the implementation. The right thing would be like this: template <typename T> T* DAO<T>::find(T* entity) { return nullptr; } And as far as I know, template…