Beginners - July 2018 (Page 7)

new and delete vs vector
 
C++ beginner here. I am learning dynamic memory allocation recently and trying to compare with vector<> with a small code snippet shown below. #include<io...
[2 replies] Last: Thanks Peter! That was a lurking mistake for me :) (by platypus1989)
by darkX
Modular multiplicative inverse
 
please suggest me the most opptised algo (preferably in java) to find the Modular multiplicative inverse i am using this till now:- static int mod...
[no replies]
Count++ not adding to initial count
 
Hello, I have spent hours on this project and am hoping for some help. I have been trying to get my counts to work but every time I run the program it outputs 0...
[1 reply] : #include <iostream> #include <string> #include <fstream> #include <cc... (by JLBorges)
Segmentation fault with empty string
 
I've been in panic recently because I have code that works fine on one computer, but crashes on the server where I submit my code. I have a class called "Perso...
[15 replies] Last: Sometimes when people have been reluctant to post code they can find s... (by dhayden)
by clonxy
How to change a dynamic 2d array from another func
 
I'm trying to create a dynamic 2d array to play chess with only 2 pieces: White King and Black queen. The user inputs the size of the board and then I place t...
[10 replies] Last: I agree, doing a manual 2D->1D indexing (y*width + x) is very nice (it... (by Ganado)
Incrementing value of variables in an array
 
Can anyone tell me how I'm supposed to increment in variables that are in arrays? I have tried looking on the internet but they aren't very clear. Also, how am ...
[5 replies] Last: Your problem lies in the fact that you are trying to increment the enu... (by Misenna)
Cannot Open Source File
 
In the Main Test File, the statement #include "frac93.hpp" does not work. There is a red squiggly line underneath the #include that indicates the file cannot...
[2 replies] Last: The name of the header file is "frac93.hpp". The name "frac93.hpp" is... (by phztfte1)
by ysf007
How to write o good Comparison operator ?
 
hi, I'm trying to check if two objects are equal cause I got this error XD binary '==' : no operator found which takes a left-hand operand of type 'Foo' (or t...
[10 replies] Last: If you're looking for efficiency then you might also consider which da... (by dhayden)
The importance of compile time functions?
 
What is the importance of evaluating things at compile time? int x = 10; and constexpr int x = 10; Both of these are going to give us an integer dat...
[1 reply] : It allows you to use it in places where a compile time constant is req... (by Peter87)
Difficulty with while loop
 
Hi! I just recently started learning programming and this is my first language and I have no prior experience. I am following the Bjarne Stroustrup Programmi...
[3 replies] Last: I didn't check your code 100% but it looks really good. easier to jus... (by jonnin)
File I/O Comparing numbers.
 
I have 3 lines in my file. 34532 2323 43242 523 532652 324 4325 5235 235562 If I getline, each I only have 3 cells. If I "infile >>" I will have 9 cell...
[3 replies] Last: I'll try to read your code @Ganado. I need to see how I can compare th... (by seungyeon)
Arrays, tables and void functions... help...
 
Can anyone figure out how to read the next value from an input file and store it in array table while using a void function that is not letting you do it the ...
[1 reply] : void functions can take parameters. void foo(ifstream &ifs) //this i... (by jonnin)
by watted
help with oop exercise (rectangular Matrix)
 
Hello everybody,i need help in exercise: 1.write a class of rectangular matrix in c++ a.define the operators +,-,+=,-= and the matrix multiplication(includi...
[2 replies] Last: This looks like a lot of fun. Write and you will have fun, too! Br... (by icy1)
by Ch1156
How to create a timer using C++ only and no windows API
 
I am writing a game similar to the Fallout shelter part where they explore the wasteland. I would like the game to do something every minute like say some dialo...
[12 replies] Last: #include <iostream> #include <vector> #include <string> #include <chr... (by icy1)
C++ Void and cout
 
Hello everyone, Could you please help me to understand why the program doesn't see the input data? I need it to display the hours and minutes and it shows ...
[8 replies] Last: An example of correct function pass by reference. #include <iostrea... (by Manga)
Implementation of Comparison Operator
 
I am reading Object-Oriented Programming In C++ by Nicolai M. Josuttis. In Chapter 4 of the book, he provides a header file but no source file for the header f...
[3 replies] Last: I retyped the test program into another file, and the source file "fra... (by phztfte1)
Google test in CLion - Unit test function using gmock
 
bool bank::read1(int duration){ int num_votes = take_vote(&party, leader, duration); if (num_votes > 0){ int count_votes = read(dup, buf...
[4 replies] Last: I think in its current state the function isn't testable since it depe... (by Thomas1965)
by SulPC
Code Optimization
 
In what ways could the following code be optimized? It's a basic program state function to all function loops based on its state. main.ccp #include <iostream...
[2 replies] Last: even with such a small program I would not use the global. optimiza... (by jonnin)
by Donut
Functional Decomp
 
Newbie with another question for the experts...I am teaching myself C++ and have spent a fair amount of time reading on this site to help better understand how ...
[1 reply] : you can take the file I/O and remove all of it into a function, and ha... (by jonnin)
July 2018 Pages: 1... 56789... 17
  Archived months: [jun2018] [aug2018]

This is an archived page. To post a new message, go to the current page.