Posts by zentrunix • 5,511 points
272 posts
-
0
votes1
answer87
viewsA: Problem due to queuing
The error message you placed does not match the text: there is no command FilaAluno[fimfila].nome = FilaAluno.nome; on the lines of code you showed... But there is an error in this line…
-
0
votes1
answer77
viewsA: Project shared with Cmake
I can not get a general idea of your project, but anyway will a suggestion of how I would do, assuming that Projetob and Projetoc generate two libs that are used by the project A...not tested, may…
-
2
votes3
answers972
viewsA: How to get the buffer from the socket?
It is possible to use the function ioctl (on Windows, ioctlsocket) with argument FIONREAD, to get the information you want, but never I saw it being used. Among other things, because when you do the…
-
1
votes2
answers10403
viewsA: How to separate a string into pieces?
In C++ there is no native split function for strings. Searching the subject is a huge variety of ways to separate a string. Some examples I found interesting. Example 1 #include <iostream>…
-
2
votes3
answers171
viewsA: Is it safe to create an object pointer in the stack indirectly?
Example showing the undefined behavior when using the resource used by OP. // arquivo ptrtest.cpp #include <iostream> using namespace std; class A { public: int x; A(); A* getThis() { return…
-
0
votes1
answer107
viewsA: Overload of Operator in C++
Your question is confused but I think I understand what you want: you want to create a Manipulator (this is the technical term) called bin, converting a number to binary, in the same way as…
-
0
votes1
answer388
viewsA: Use of Thread in c++
You need protect the vector of primes with a mutex, so that only one thread at a time can change this vector. Usually data structures cannot be changed by more than one thread at the same time, this…
-
2
votes2
answers745
viewsA: Set values or not in c++variables
Global variables or static variables not initialized by the programmer are initialized by the compiler with the default constructor. In practice, variables of the "native" types (int, char, bool,…
-
4
votes1
answer3755
viewsA: Function pointer in a C++ class
Pointer to method is a technique not widely used (I think), and so few people know. I had to do some research to find out that you need to use additional parentheses when using the pointer. Note…
-
2
votes1
answer455
viewsA: Operator overload ==
The error is in a part of the code that was not shown by OP. I’m putting the modified code because the original code is a bad example of C++. #include <iostream> using namespace std; class…
-
0
votes1
answer253
viewsA: Export methods from a dll in C++
Visual Studio 2005 Compiler (used in command line) DLL #include <iostream> using namespace std; namespace N { class __declspec(dllexport) C { public: void display(); static C* createNewC() {…
-
1
votes1
answer326
viewsA: How do I stop a for loop that stores the values of strings typed in C++?
Your code in http://cpp.sh/9x2n3 has a line like this for (int y = 0; y < med.size(); x++) { This line repeats indefinitely. Obvious correction: for (int y = 0; y < med.size(); y++) {…
-
1
votes2
answers909
viewsA: How to use Operator= to copy a pointer vector?
Usually classes that have pointers as members need to implement 3 methods: copy constructor, assignment and destructor. It may also be necessary to implement the "move constructor" and "move…
-
1
votes2
answers494
viewsA: How to calculate the Xmin,Xmax,Ymin,Ymax of an object?
The standard library from C++11 has the algorithms "min_element", "max_element" and "minmax_element" that work with element sequences. Below is an example of how to use. #include <algorithm>…
-
1
votes3
answers603
viewsA: How to check any received type (upper or lower case)?
There is no native case-insensitive string comparison function in C++. On Windows you could use "stricmp" and Linux "strcasecmp". In pure C++ it takes a little extra code. Below, a way to make this…
-
1
votes1
answer320
viewsA: parameters for function : const reference and constant data pointer
In principle it makes no difference, since the obvious implementation of a parameter by reference is simply a pointer.
-
3
votes1
answer118
viewsA: When a function is executed a new thread object is created?
Question: this means that every time the body/scope of a function is executed a new thread is created ? Answer: nay. Question: or this happens with all kinds of scope ? Answer: nay. Explanation: A…
-
3
votes1
answer77
viewsA: Running gives me a mistake and I can’t identify
The function fgets needs a "file Pointer" (FILE*) to read a file. To get a Pointer file you need to "open" the file, with the function fopen. The function fclose "closes" the file referenced by a…
-
2
votes1
answer67
viewsA: How do Overload the assignment operator into a class that contains vector?
You can use the command forto traverse an array, and you can use the method push_back to add elements to a vector. In the example below, the functions copy_from and release_old need to be…
-
2
votes2
answers159
viewsA: I can’t keep the string
Use fgets to read a line. Do not use gets, is grounds for dismissal for just cause. #include <stdio.h> void ex51(char *nome_ficheiro) { char frase[100]; printf("Introduza o texto que quer…
-
1
votes1
answer128
viewsA: Create Project from DLL
You do not "turn" the headers into C. These headers are just "statements", not executable code. If you are creating a service Provider wosa/xfs, your mission is to create a DLL that implement the…
-
1
votes3
answers4668
viewsA: How to compare one to one all the elements of two vectors?
It is possible to compare element by element between two vectors (actually between any two sequences specified by Iterators) through the algorithm "Mismatch". The "comparison function" is a generic…
-
3
votes3
answers844
viewsA: Sorting of object vectors
Looks like a program conversion from C# to C++... Below a corrected C++11 version, removing the C#ismos: #include <vector> using std::vector; #include <algorithm> using std::sort;…
-
0
votes6
answers3667
viewsA: Are there objective advantages to a language being "case sensitive" or not?
In languages that require declaration of variables before their use the general question is irrelevant. In languages that do not require declaration of variables before their use (typically…
-
2
votes1
answer77
viewsA: In the Web context what is a proxy?
A proxy is an "intermediary" between a client and a server. A typical proxy use case is server balancing. Let’s assume that a site has 10 servers. However, the site only receives requests by a…
-
0
votes3
answers1496
viewsA: What is DTD (Document Type Definition)?
Roughly and informally, a DTD is a "schema" for a class of XML documents. When using a XML parser with validation and informing the DTD to the parser, it can then accept an XML document as valid or…
-
0
votes2
answers7739
viewsA: How to receive multiple values on the same line?
A slightly more idiomatic solution avoiding using new/delete and native arrays. #include <iostream> #include <vector> using namespace std; int main() { int vecSize; cout << "Digite…
-
1
votes3
answers2121
views -
0
votes1
answer436
viewsA: Error reading C++ file
The program is correct. The problem is in your environment. As commented by @stderr, either the file doesn’t exist, or is in another directory, or has another name, or something like that. P.S. " In…
-
0
votes2
answers714
viewsA: Separating substrings and storing in C++ variables
One way is this, considering that strings are separated only by spaces. There must be other. #include <iostream> #include <sstream> #include <string> #include <vector> using…
-
1
votes2
answers281
viewsA: Doubt: I did not understand why of continuation
The program has several errors, including logic, I will stick to the most obvious, I will not correct the logic. First, the data entry: printf("\n Digite a idade:"); scanf("%d", &idade);…
-
2
votes1
answer234
viewsA: Attempt to index local 'rkgdat' (a nil value)
The "load_data" function failed, and the "rkgdat" variable was initialized with nil. You need to put a test right after "load_data": local rkgdat = load_data('data/ranking/' .. msg.chat.id ..…
-
0
votes6
answers35893
views -
4
votes1
answer472
viewsA: How to sort a column of a file without ordering the rows?
Script: #!/bin/bash INPUT=$1 OUTPUT=$2 awk '{ print $1 }' $INPUT > $$.1 awk '{ print $2 }' $INPUT | sort -n > $$.2 awk '{ print $2 }' $INPUT > $$.3 paste $$.1 $$.2 $$.3 > $OUTPUT rm $$1…
-
0
votes2
answers691
viewsA: How to avoid "Warning: ISO C++ forbids variable length array ːfilename' [-Wvla]" error in C++11
In C++ I would do the following: string fileName = filePath + "/" + filePrefix + date + to_string(image_counter++) + fileExtension + "\n"; cv::imwrite(fileName.c_str(), frame); A deficiency of the…
-
1
votes2
answers5430
viewsA: a Function-Definition is not allowed here before '{' what does this error mean?
You set the function definition "menuAlunoCurso" before the final key "}" of the previous function. Something like that: void func() { // bla // bla // bla void menuAlunoCurso(){ // bla // bla //…
-
3
votes4
answers8575
viewsA: How to take system time and save in a variable?
To just "save" the current C++ way of doing is #include <chrono> using namespace std::chrono; ... ... auto now = system_clock::now(); To work with this new infrastructure is a little more…
-
2
votes2
answers233
viewsA: Error: "invalid operands to Binary Expression ('char *' and 'char *')"
You’re trying to put two pointers together msg = "Ao Sr.:\n" + pessoa->nome; This is an operation that doesn’t exist in C. What you’re probably trying to do is this: static const char saudacoes[]…
-
1
votes1
answer458
viewsA: How to find the lowest value of a moon matrix?
As suggested by @ederwander, there was a command to prepare the generation of pseudo-random numbers. Otherwise your logic is correct. #!/bin/lua math.randomseed(os.time()) -- faltava isso matriz =…
-
2
votes1
answer496
viewsA: Address and UDP destination ports do not appear
If you have an UDP server that has made a "bind" on a certain port then it will not even appear the IP and the target port, this is normal. Even if there is UDP traffic for this service will not…
-
1
votes1
answer57
views -
0
votes1
answer18
viewsA: how to ask Make to only run one target after the end of another when using multicore
Run the make sequentially: make -j4 clean; make -j4 all Update: You can do something like that: all: clean real_all @echo ended all clean: @echo cleaning... real_all: target1 target2 ... @echo ended…
-
2
votes2
answers257
viewsA: How could I enter the structs in a list?
Just to complement, this is the same source created by @Maniero, but with two things I think are cool: smart pointers, and use of "move" operation instead of copying the object. #include…
-
5
votes2
answers3526
viewsA: Why is 'ç' converted to %C3%A7 URL, not %E7?
This string %C3%A7 is the UTF-8 encoding of the ç character for use in Urls. Reference: http://www.w3schools.com/tags/ref_urlencode.asp https://en.wikipedia.org/wiki/UTF-8 Another interesting page:…
-
3
votes3
answers579
viewsA: How to store variables in.txt files
There is no automatic way to do this, it has to be explicitly programmed. In the normal output of the program you write in a file of your choice the data you think will be needed in the next…
-
0
votes1
answer49
viewsA: Deck(C++): Abort Trap 6
Change it here while(i <= sack_weight->size()) so here while (i < sack_weight->size()) Also change in other similar commands.…
-
5
votes2
answers199
viewsA: Is there any difference between the ways of declaring classes in C++?
Methods defined in the class declaration are automatically considered "inline" by the compiler. The compiler can generate "inline" code for these methods, that is, it does not create a function that…
-
1
votes2
answers2629
viewsA: Code::Blocks - error: Stray ' 240'
Typo error: has an invalid character somewhere in your source, probably an "á". \240 = 128 + 32 = 160 (Alt+160 on Windows is "á")
-
0
votes1
answer1077
viewsA: C Circular Double Chained List Descending Ordering
I find it difficult to keep finding this type of problem with pointers, I preferred to create a new example. #include <stdlib.h> #include <stdio.h> typedef struct Item { int height;…
-
2
votes1
answer514
viewsA: How do I eleminate repeated numbers in c
Surprisingly this problem is relatively complex. To be clear, I preferred to do a small test program, and I’m not ordering (I already provide the numbers in order). #include <stdio.h> void…