General C++ Programming - June 2020 (Page 5)

by doug4
One more line of code I need to make it work
 
I would try this if (y == 0) { std::cout << "Cannot divide by zero. Operation aborted..." << std::endl; } else if ( (x % y) == 0) { std::cout << x << ...
[7 replies] Last: And the spampost is gone :) (by MikeyBoy)
Output affected by placement of delete statement
 
Hello, I'm a computer science student and am working on a homework problem. I have already solved it; however, I noticed some odd behavior based on where I put...
[5 replies] Last: going out of bounds of a block of memory can cause any of many unpredi... (by jonnin)
Currency to words C++
 
Im trying to make a code that displays currency such as (312,12) in words (three hundred twelve dollars and twelve cents. #include <iostream> #include <str...
[4 replies] Last: Thanks dutch for your help i was able to get the code working. after y... (by somedude)
swap
 
do u know whats the difference between storage.swap(new_storage) and std::swap(storage,new_storage), also does it have to be std::storage.swap(new_storage) if i...
[1 reply] : Typically, prefer the specialized a.swap(b) over the more generic s... (by mbozzi)
template
 
#ifndef FAST_QUEUE_H #define FAST_QUEUE_H #include <iostream> #include <vector> #include <algorithm> #include <exception> template <typename T> class FastQueue...
[4 replies] Last: thanks (by closed account jGAShbRD)
Searching for a word in text file
 
Hi im trying to write a program that reads in a text file. The user can search for a specific word and it will output another file. The new file will have the l...
[2 replies] Last: Maybe like this: #include <iostream> #include <fstream> #include <str... (by Thomas1965)
mod help
 
i have some variables. int first = shows the start of queue int count = size of my vector int number = number of elements in my vector int index= gets the value...
[1 reply] : #include <iostream> int main() { const int Capacity = 4; ch... (by dutch)
Bernoulli formula with more than one k
 
I want to make a program in which I calculate the probability with Bernoulli for multiple k's (for example if P(X<=2), so k is 0,1,2). I have made the follow...
[1 reply] : You shouldn't keep inputting new k values. Just input the maximum one.... (by lastchance)
by volang
Size of a forward_list
 
I dont want to keep track of its size on my own, so I wonder if I instead can update a member variable after each insertion? Or add limit, that makes the inser...
[16 replies] Last: It could still be possible to have O(1) splice with size. Like jonnin ... (by helios)
testing.
 
im getting an error when i was trying to test my code i got a main.cpp and a class main.cpp:5:13: error: use of undeclared identifier 'T' FastQueue<T...
[1 reply] : You have to put an actual type in the <T> when declaring an object. Fa... (by Ganado)
vector
 
if i have a vector a of size 10 holding 10 elements and another vector b of size 20 holding 10 elements if i swap a and b will a have size 20 holding 10 elemen...
[2 replies] Last: for anything you swap, the a becomes b, and b becomes a, FULLY, not pa... (by jonnin)
Trying to calculate with the Bernoulli formula
 
I am willing to calculate with the Bernoulli formula. For that I have made the following code: #include <iostream> #include <math.h> using namespace std; i...
[8 replies] Last: Ah, duh. (by helios)
Loop
 
How can I print 2 line like this to console? 1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20 The first li...
[11 replies] Last: try this .... #include<iostream> using namespace std; int main() { ... (by aniksh44)
vector help
 
i have a vector<Typename> which is a container with unknown amount of elements. i have a int first = 0 which corresponds to first element. and last which is las...
[1 reply] : Is this a continuation of: http://www.cplusplus.com/forum/general/2710... (by keskiverto)
by Vycues
Which event should code go to restrict areas where a picture box is dropped on a form
 
I am trying to make a card game in a windows form. I want to check the image string name in the picture box before it is and dropped using the mouse onto a pile...
[no replies]
by Ema00
Login function
 
Hello everyone, in the code below I tried to make a simple staff management program for school, I want to insert the Login function to appear when the program c...
[6 replies] Last: A tip for making your code cleaner and better looking: You can add a f... (by miguelol)
list/array of constant pair values at compile time
 
How do we have a list/array of constant pair values at compile time so it would be passed as two arguments of function invoked repeatedly as many times as the a...
[7 replies] Last: Possibly relevant? http://www.cplusplus.com/forum/general/271007/ (by helios)
by volang
Map or unordered map?
 
I have a map where the order never matters. The only important thing is that I get direct / fast access to the value of the specified key. Maintaining the ...
[7 replies] Last: That's true (except if you don't need access by key) The OP specific... (by dhayden)
for enum cannot work
 
Why is this not working enum L{ j, k, l }; int main(){ for ( int i : L) cout<< i<<"\n"; }
[2 replies] Last: That’s not how for loops work. You should try using a switch sta... (by Gringoliath)
exceptions
 
template <typename T> T & FastQueue<T>::front(){ if (number_of_elements == 0) throw std::out_of_range; else{ return storage.at(first); } } is t...
[1 reply] : It's a type, not a value, so throw std::out_of_range(); . (by helios)
June 2020 Pages: 1... 3456
  Archived months: [may2020] [jul2020]

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