General C++ Programming - September 2020

by kitfox
How to use smart pointers to expose internal parts of a class?
I'm trying to figure out how to adapt code written using raw pointers to use smart pointers. I have several classes where one class (let's call it Alpha) conta...
Sep 30, 2020 at 7:57pm
[3 replies] Last: Smart pointers do not replace plain pointers -- that's a common misc... (by mbozzi)
by kitfox
Best way to allocate a block of memory?
I want to allocate a large block of memory to store image data. It will be several kilobytes in size and is basically just a large block of bytes representing ...
Sep 30, 2020 at 3:29pm
[4 replies] Last: If you want to dynamically manage memory and don't want to use std::v... (by deleted account xyzzy)
Is Java easy to learn after C++?
Hello. Does anyone know if Java (or, whatever the game 'Minecraft' is written in) is easy to learn after C++? I've only learned C++ so far when it comes t...
Sep 30, 2020 at 2:29pm
[9 replies] Last: the biggest problem I have with java after c++ is that there are a doz... (by jonnin)
Reading hex offsets/data from ifstream file?
Hello. Can anyone tell me if it is possible to read a hex offset such as 0x00000001 (0x1??) Like in a hex editor??? Ummm... I guess that's my question. Thanks...
Sep 30, 2020 at 1:26pm
[3 replies] Last: int offset; mystream.read((char*)&offset, sizeof(offset)); // if th... (by dhayden)
by Borneq
Odd template
In type_traits I can see: // [func.require] paragraph 1 bullet 1: struct __result_of_memfun_ref_impl { template<typename _Fp, typename _Tp1, typename......
Sep 30, 2020 at 11:00am
[2 replies] Last: To explicitly answer each of these: std::declval is a function, so th... (by MikeyBoy)
#ifndef include guard help!
Hello. I am new to using #ifndef, #ifdef, #endif and such. I put the following at the top of my header file: #ifndef INCLUDE_H #define INCLUDE_H And an #end...
Sep 30, 2020 at 4:18am
[13 replies] Last: Problem solved. Thank you all for helping!! (by SirEnder125)
by its007
Filling 3-d array with random number with conditions
Hello all, First off, I would like to thank you for reading this. I am grateful for any help/hints I can get. I have a dynamically allocated 3-d array (ex: ar...
Sep 30, 2020 at 2:02am
[5 replies] Last: Thank you jonnin and coder777! I appreciate the help much very much. ... (by its007)
Manipulating an array (creating destructor, shifting elements forward/back and printing the array)
Need help finishing up the yet to be defined functions in this chunk of code. #include <iostream> using namespace std; // You need to define the functions rem...
Sep 30, 2020 at 1:20am
[1 reply] : moveTowardEnd( index ) { /* s = size WHILE s > index : ... (by nuderobmonkey)
User input after *argv[] input
Hello. I would like to know how to get a file name input into int main(int argc, char *argv ) Like the user inputs: --file text.txt and a file is made c...
Sep 29, 2020 at 7:25pm
[8 replies] Last: Thank you. I'll try to remember all this stuff... I should have learn... (by SirEnder125)
Certain input value causing crash
Dear Users, The code blow keeps craching for input 15. I thought it was some Windows 7 issue. Then I installed a fresh copy of Windows 10. But still the exe ke...
Sep 29, 2020 at 4:36pm
[5 replies] Last: Change to int* p = new int ; p = 2, p = m; works ok on my win... (by seeplus)
C++ code for reading text from file? (help)
Hello. I was wondering if anyone could tell me how to do this. Read the text after the inputted label from this file: input.txt Msg1::"Hello world!" ...
Sep 29, 2020 at 2:13am
[4 replies] Last: just do getlines and discard the ones you do not want to skip a line o... (by jonnin)
Does destructor of a polymorphic base class that is protected need to be virtual?
If I have a base class for an inheritance tree, and the destructor is declared protected, do I still need to define this method as virtual? Why if I am not goin...
Sep 28, 2020 at 8:28pm
[3 replies] Last: thanks!! (by JUANDENT)
How do I use a boolean vector with if-else?
Let me explain exactly what I mean. I've got a recursive function that works with roughly the following pseudocode int funct (vectorlist1, param2, ..., vector...
Sep 28, 2020 at 7:30pm
[1 reply] : .at is notably slower than notation because it checks i to be valid.... (by jonnin)
by jerryd
wofstream problem
cplusplus forum, Windows 7, MS VS 2017, C++ I have a wstring that contains a unicode character and want to use it as a file name. wstring = filep...
Sep 28, 2020 at 12:05am
[7 replies] Last: cplusplus forum, I was able to find a way to create a windows file na... (by jerryd)
What does ^= mean and how do I use it?
I've seen this operator in c++ codes and I don't know what it means. Thanks for answers in advance.
Sep 27, 2020 at 7:40pm
[4 replies] Last: Ah, thanks for explaining this. I'll try using this in my code. (by SirEnder125)
Encryption code not working
Hello. Can anyone here tell me why this code won't work (you can run it to see what I mean) #include <include.h> #include <encrypt.h> int main() { char a; ...
Sep 27, 2020 at 3:48am
[2 replies] Last: I figured out what was wrong, I should have done: data = encrypt(dat... (by SirEnder125)
How to combine hash values using std::hash
I have a type with 2 int data members. I want to calculate a GOOD hash value and since std::hash exists I thought I would use it - after all it must be GOOD to ...
Sep 26, 2020 at 9:45pm
[12 replies] Last: perfect hashing is usually reserved for a static set of known data suc... (by jonnin)
my compiler says expected primary expression before '<<'
#include <string> #include <fstream> using namespace std; struct TempScale { double fahrenheit, centigrade; }; struct Reading { int windSpeed; ...
Sep 26, 2020 at 8:03pm
[2 replies] Last: You're also attempting to use the name of a class as if it were an obj... (by Ganado)
by AmirRN
Why const reference string
Hi everyone, I just wrote this piece of code to test something, but it didn't go through the GCC-compiler because of the following error: C:\Project\TESTS\QtC...
Sep 26, 2020 at 2:22pm
[1 reply] : is not why you need a const reference, but why do you need a non-const... (by ne555)
Eight Queens Problem 2-D Array Help
Hi I am currently trying to work on creating a function where it determines if a queen is under attack by another queen and returns if there is a queen in the ...
Sep 26, 2020 at 8:36am
[1 reply] : TBH, the whole idea of storing the row in a 'Queen' object, and the co... (by salem c)
September 2020 Pages: 1234
  Archived months: [aug2020] [oct2020]

This is an archived page. To post a new message, go to the current page.
Registered users can post in this forum.