15,907,281 members
Home / Discussions / C / C++ / MFC

# C / C++ / MFC

 Re: RegQueryValueExW vs RegQueryValueExA Dave Kreskowiak18-Jun-23 4:42 Dave Kreskowiak 18-Jun-23 4:42
 mutex problem PV202314-Jun-23 20:51 PV2023 14-Jun-23 20:51
 Re: mutex problem Richard MacCutchan14-Jun-23 21:17 Richard MacCutchan 14-Jun-23 21:17
 Re: mutex problem jschell15-Jun-23 2:33 jschell 15-Jun-23 2:33
 Is there a way to add all the elements of a vector to an integer sequentially? puckettrobinson6755-Jun-23 18:16 puckettrobinson675 5-Jun-23 18:16
 Re: Is there a way to add all the elements of a vector to an integer sequentially? Victor Nijegorodov5-Jun-23 20:39 Victor Nijegorodov 5-Jun-23 20:39
 Re: Is there a way to add all the elements of a vector to an integer sequentially? Richard MacCutchan5-Jun-23 21:30 Richard MacCutchan 5-Jun-23 21:30
 Re: Is there a way to add all the elements of a vector to an integer sequentially? CPallini5-Jun-23 21:44 CPallini 5-Jun-23 21:44
 Quote:Is there a way to add all the elements of a vector to an integer sequentially?Yes, there are, at least, three different ways: C++ ```#include #include #include using namespace std; void dump (vector v) { for (auto x :v ) cout << x << " "; cout << "\n"; } int main() { { // method 1: access items by indices vector v{1,2,3}; int c = 4; for (size_t n = 0; n v{1,2,3}; int c = 4; for (auto & x : v) { x += c; } cout << "method 2: "; dump(v); } { // method 3: use 'transform' of the algorithm library vector v{1,2,3}; int c = 4; transform(v.begin(), v.end(), v.begin(), [=](int x){ return x+c; }); cout << "method 3: "; dump(v); } }``` Quote:As a side note, is there a way to add a repeating number to an integer to infinity?Yes, but this way the addition will overflow. Try: C++ ```#include using namespace std; int main() { int i = 1; int last_i; int c = 4; for (;;) { last_i = i; i += c; if ( i < last_i) break; } cout << "unfortunately, (" << last_i << "+" << c << ") makes " << i; }``` "In testa che avete, Signor di Ceprano?" -- Rigoletto
 Image compression Calin Negru30-May-23 9:09 Calin Negru 30-May-23 9:09
 Re: Image compression OriginalGriff30-May-23 9:18 OriginalGriff 30-May-23 9:18
 Re: Image compression Calin Negru30-May-23 23:52 Calin Negru 30-May-23 23:52
 Com Automation latest library for working with ms excel. I_am_nayak22-May-23 18:34 I_am_nayak 22-May-23 18:34
 Re: Com Automation latest library for working with ms excel. _Flaviu22-May-23 20:28 _Flaviu 22-May-23 20:28
 Re: Com Automation latest library for working with ms excel. Victor Nijegorodov22-May-23 22:47 Victor Nijegorodov 22-May-23 22:47
 CPU Usage Richard Andrew x6419-May-23 15:56 Richard Andrew x64 19-May-23 15:56
 Re: CPU Usage Dave Kreskowiak19-May-23 17:48 Dave Kreskowiak 19-May-23 17:48
 Re: CPU Usage harold aptroot19-May-23 18:53 harold aptroot 19-May-23 18:53
 Re: CPU Usage Greg Utas20-May-23 0:13 Greg Utas 20-May-23 0:13
 Re: CPU Usage Gerry Schmitz20-May-23 4:04 Gerry Schmitz 20-May-23 4:04
 Re: CPU Usage `Randor` 20-May-23 6:38 `Randor` 20-May-23 6:38
 Re: CPU Usage Richard Andrew x6420-May-23 10:21 Richard Andrew x64 20-May-23 10:21
 Re: CPU Usage Dave Kreskowiak20-May-23 19:30 Dave Kreskowiak 20-May-23 19:30
 Re: CPU Usage David Crow22-May-23 7:49 David Crow 22-May-23 7:49
 Re: CPU Usage Dave Kreskowiak22-May-23 8:43 Dave Kreskowiak 22-May-23 8:43
 Re: CPU Usage Dave Kreskowiak20-May-23 10:28 Dave Kreskowiak 20-May-23 10:28
 Last Visit: 31-Dec-99 18:00     Last Update: 28-May-24 9:52 Refresh ᐊ Prev1...37383940414243444546 Next ᐅ