notes/.config/newsboat/reddit_rss/cpp_questions.rss
2023-01-28 05:22:19 -08:00

1 line
No EOL
62 KiB
XML

<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><category term="cpp_questions" label="r/cpp_questions"/><updated>2023-01-28T12:50:57+00:00</updated><icon>https://www.redditstatic.com/icon.png/</icon><id>/r/cpp_questions.rss</id><link rel="self" href="https://www.reddit.com/r/cpp_questions.rss" type="application/atom+xml" /><link rel="alternate" href="https://www.reddit.com/r/cpp_questions" type="text/html" /><subtitle>a subreddit for c++ questions and answers</subtitle><title>c++ questions and answers</title><entry><author><name>/u/rectal_smasher_2000</name><uri>https://www.reddit.com/user/rectal_smasher_2000</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Hi everyone!&lt;/p&gt; &lt;p&gt;This post is basically a sticky that everyone should read prior to posting in order to acquaint themselves with rules and features of this subreddit. Since it&amp;#39;s quite obvious that many of our new posters have trouble with code formatting, in turn making life difficult for those of us who want to help; the first item in this sticky will be a short tutorial on proper code formatting. If need be, we&amp;#39;ll hide posts that haven&amp;#39;t formatted their code correctly until OP fixes the post in question.&lt;/p&gt; &lt;p&gt;By the way, this can be a discussion thread as well, so feel free to post your opinions and suggestions. Also, we&amp;#39;ll keep adding new items as they come up.&lt;/p&gt; &lt;hr/&gt; &lt;h3&gt;ITEM 1 - FLAIRS&lt;/h3&gt; &lt;hr/&gt; &lt;p&gt;We&amp;#39;ve introduced link flairs, as well as &lt;a href=&quot;/u/AutoModerator&quot;&gt;/u/AutoModerator&lt;/a&gt;!&lt;/p&gt; &lt;p&gt;So far, we have two link flairs - &lt;a href=&quot;#open&quot;&gt;OPEN&lt;/a&gt; and &lt;a href=&quot;#solved&quot;&gt;SOLVED&lt;/a&gt;. You, as regular subscribers should have access only to the &lt;a href=&quot;#solved&quot;&gt;SOLVED&lt;/a&gt; flair, since &lt;a href=&quot;/u/AutoModerator&quot;&gt;/u/AutoModerator&lt;/a&gt; will automatically flair every new post as &lt;a href=&quot;#open&quot;&gt;OPEN&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;In addition, we&amp;#39;ve added links in the sidebar to allow you to search by flair.&lt;/p&gt; &lt;p&gt;Of course, we would be very appreciative if you marked your post as &lt;a href=&quot;#solved&quot;&gt;SOLVED&lt;/a&gt; if someone actually helps you solve your problem. &lt;/p&gt; &lt;p&gt;Thanks to &lt;a href=&quot;/u/ftbmynameis&quot;&gt;/u/ftbmynameis&lt;/a&gt; for the great idea!&lt;/p&gt; &lt;p&gt;These are the steps you need to take in order to flair up your post:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Click on the &lt;a href=&quot;http://i.imgur.com/UxlZKGK.png&quot;&gt;flair button&lt;/a&gt; on your post.&lt;/li&gt; &lt;li&gt;Select &lt;a href=&quot;#open&quot;&gt;OPEN&lt;/a&gt; or &lt;a href=&quot;#solved&quot;&gt;SOLVED&lt;/a&gt; from the &lt;a href=&quot;http://i.imgur.com/uvBbPwZ.png&quot;&gt;pop-up menu&lt;/a&gt;.&lt;/li&gt; &lt;li&gt;Save&lt;/li&gt; &lt;/ol&gt; &lt;hr/&gt; &lt;h3&gt;ITEM 2 - CODE FORMATTING&lt;/h3&gt; &lt;hr/&gt; &lt;p&gt;If you want to post a snipper of code, and do it by simply pasting it into the text box here on reddit, in the vast majority of cases, it will not be formatted correctly, as the code needs to be preceded by four whitespace (spaces) characters. So here&amp;#39;s a neat little trick to do this, which requires the least hassle.&lt;/p&gt; &lt;p&gt;Say you have a little snipper of code in your favourite text editor, like this: &lt;a href=&quot;http://i.imgur.com/fJzIQiD.png&quot;&gt;http://i.imgur.com/fJzIQiD.png&lt;/a&gt;.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Select the desired snippet of code and you should have something that looks like this: &lt;a href=&quot;http://i.imgur.com/08F5Tdu.png&quot;&gt;http://i.imgur.com/08F5Tdu.png&lt;/a&gt;&lt;/li&gt; &lt;li&gt;Now that your code is selected, press TAB once to indent it and end up with this: &lt;a href=&quot;http://i.imgur.com/aYwnbXf.png&quot;&gt;http://i.imgur.com/aYwnbXf.png&lt;/a&gt;&lt;/li&gt; &lt;li&gt;You&amp;#39;ll notice that the indentation on the first line is not selected; this is bad. Select the desired snippet of code again, but taking care to select all the empty space that&amp;#39;s been indented as well, and you should have something like this: &lt;a href=&quot;http://i.imgur.com/h2hKibm.png&quot;&gt;http://i.imgur.com/h2hKibm.png&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;Now, all you have to do is copy and paste this code into a text box here on reddit, and you should end up with pretty and legible code like this:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt; int main() { std::cout &amp;lt;&amp;lt; &amp;quot;Hello World!&amp;quot; &amp;lt;&amp;lt; std::endl; } &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Please learn to properly format your code, or else...&lt;/p&gt; &lt;hr/&gt; &lt;h3&gt;ITEM 3 - INLINE CODE&lt;/h3&gt; &lt;hr/&gt; &lt;p&gt;Short one - if you want to type out one line of code that is properly formatted, say &lt;code&gt;std::vector&lt;/code&gt;, you can put it in those weird single quotes that I don&amp;#39;t know the proper term for - ` - it&amp;#39;s located on the tilde (~) key, and laugh as you might at the triviality, it took me longer than I&amp;#39;d care to admit to figure this out.&lt;/p&gt; &lt;p&gt;Example: `std::vector` yields &lt;code&gt;std::vector&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Digression - this is the same way code formatting works on Stackoverflow.&lt;/p&gt; &lt;hr/&gt; &lt;h3&gt;ITEM 4 - SPOILER TAG&lt;/h3&gt; &lt;hr/&gt; &lt;p&gt;Just a quick addition - spoiler tags. If for some reason you want to mark a portion of text or code as a spoiler, thus hiding it until a user hovers over said code, you can use the spoiler tag.&lt;/p&gt; &lt;p&gt;The general format of a spoiler tag is as follows - [Spoiler content here](/spoiler). For example:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Say I want to hide &amp;quot;Hello world!&amp;quot;, I would do it like this: [Hello world!](/spoiler) and get this: &lt;a href=&quot;/spoiler&quot;&gt;Hello world!&lt;/a&gt;&lt;/li&gt; &lt;li&gt;If I want to hide a line of code, say, &lt;code&gt;std::cout &amp;lt;&amp;lt; &amp;quot;Hello world!&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;/code&gt;, I would do it like this: &lt;/li&gt; &lt;li&gt;[`std::cout &amp;lt;&amp;lt; &amp;quot;Hello world!&amp;quot; &amp;lt;&amp;lt; std::endl;`](/spoiler) and get this: &lt;a href=&quot;/spoiler&quot;&gt;&lt;code&gt;std::cout &amp;lt;&amp;lt; &amp;quot;Hello world!&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;/code&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;hr/&gt; &lt;h3&gt;ITEM 5 - HOMEWORK QUESTIONS&lt;/h3&gt; &lt;hr/&gt; &lt;p&gt;We get many questions along the lines of &amp;quot;can you do my homework for me&amp;quot;. While we are happy to answer specific questions - for example &amp;quot;I expected this code to work, but it doesn&amp;#39;t why?&amp;quot; or &amp;quot;what does this error message mean?&amp;quot; or even (if you&amp;#39;re lucky) &amp;quot;I wrote this for my homework, can you give me a code review?&amp;quot;.&lt;/p&gt; &lt;p&gt;However, please do not ask us to write any code in a homework question. There are several reasons for this:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;It defeats the point of setting you homework, which is to get you to write your own code.&lt;/li&gt; &lt;li&gt;Professors can usually tell.&lt;/li&gt; &lt;li&gt;It may count as plagiarism under your University&amp;#39;s rules. (And there are professors out there savvy enough to check.)&lt;/li&gt; &lt;li&gt;If you are able to get an assignment in without understanding the principles behind it you will have difficulty with other principles that are build on top of it, and the problem will snowball.&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;If you are totally lost with your problem, and can&amp;#39;t figure out how to ask the question, a good start is to break the problem down into smaller problems. For example: &amp;quot;how do I read this file into this &lt;code&gt;struct&lt;/code&gt;?&amp;quot; can become &amp;quot;how do I read a file?&amp;quot; and &amp;quot;how do I make this &lt;code&gt;struct&lt;/code&gt;?&amp;quot;. The smaller you can make the problem, the easier it is for you and us to handle.&lt;/p&gt; &lt;hr/&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/rectal_smasher_2000&quot;&gt; /u/rectal_smasher_2000 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/48d4pc/important_read_before_posting/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/48d4pc/important_read_before_posting/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_48d4pc</id><link href="https://www.reddit.com/r/cpp_questions/comments/48d4pc/important_read_before_posting/" /><updated>2016-02-29T23:02:16+00:00</updated><published>2016-02-29T23:02:16+00:00</published><title>IMPORTANT - READ BEFORE POSTING</title></entry><entry><author><name>/u/SiriPsycho100</name><uri>https://www.reddit.com/user/SiriPsycho100</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Should I learn C++ using the latest features from C++23? Or should I learn using more commonly used versions in industry like C++17 or C++11?&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/SiriPsycho100&quot;&gt; /u/SiriPsycho100 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n9dw7/which_version_of_c_should_i_use_to_learn_between/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n9dw7/which_version_of_c_should_i_use_to_learn_between/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10n9dw7</id><link href="https://www.reddit.com/r/cpp_questions/comments/10n9dw7/which_version_of_c_should_i_use_to_learn_between/" /><updated>2023-01-28T07:38:12+00:00</updated><published>2023-01-28T07:38:12+00:00</published><title>Which version of C++ should I use to learn between C++23/20/17/14/11?</title></entry><entry><author><name>/u/better_life_please</name><uri>https://www.reddit.com/user/better_life_please</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;I want to know what&amp;#39;s the best practice for defining a random device object in a program?&lt;/p&gt; &lt;p&gt;I&amp;#39;m asking about: 1. Should there be only one global random device defined in a C++ program? 2. Does it need any sort of synchronization for thread safety? 3. Where should I define it? My guess is inside a source file (e.g. Application.cpp). 4. How should I make it available to the other translation units? My guess is with a declaration inside a header file (e.g. Application.hpp).&lt;/p&gt; &lt;p&gt;Something like below: &lt;code&gt; // Application.hpp extern std::random_device rand_dev; &lt;/code&gt; And: &lt;code&gt; // Application.cpp extern std::random_device rand_dev {}; &lt;/code&gt; Thank you for your attention.&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/better_life_please&quot;&gt; /u/better_life_please &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10namx0/where_to_place_the_stdrandom_device_object/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10namx0/where_to_place_the_stdrandom_device_object/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10namx0</id><link href="https://www.reddit.com/r/cpp_questions/comments/10namx0/where_to_place_the_stdrandom_device_object/" /><updated>2023-01-28T08:59:46+00:00</updated><published>2023-01-28T08:59:46+00:00</published><title>Where to place the std::random_device object?</title></entry><entry><author><name>/u/adityasheth</name><uri>https://www.reddit.com/user/adityasheth</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;here&amp;#39;s my code;&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;&lt;em&gt;#include&lt;/em&gt; &amp;lt;iostream&amp;gt;&lt;br/&gt; &lt;em&gt;#include&lt;/em&gt; &amp;lt;ctype.h&amp;gt;&lt;br/&gt; using namespace std;&lt;br/&gt; &lt;em&gt;#define&lt;/em&gt; MAX 10&lt;br/&gt; class stack {&lt;br/&gt; int arr[MAX], top = -1;&lt;br/&gt; public:&lt;br/&gt; bool isEmpty(){&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; top == -1;&lt;br/&gt; }&lt;br/&gt; bool isFull(){&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; top == MAX-1;&lt;br/&gt; }&lt;br/&gt; int size(){&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; top + 1;&lt;br/&gt; }&lt;br/&gt; void push(int &lt;em&gt;val&lt;/em&gt;){&lt;br/&gt; &lt;em&gt;if&lt;/em&gt;(isFull()){&lt;br/&gt; cout&amp;lt;&amp;lt;&amp;quot;stack oerflow&amp;quot;;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;else&lt;/em&gt;{&lt;br/&gt; top++;&lt;br/&gt; arr[top]=&lt;em&gt;val&lt;/em&gt;;&lt;br/&gt; } &lt;/p&gt; &lt;p&gt;}&lt;br/&gt; int pop(){&lt;br/&gt; &lt;em&gt;if&lt;/em&gt;(isEmpty()){&lt;br/&gt; cout&amp;lt;&amp;lt;&amp;quot;stack underflow&amp;quot;;&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; 0;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;else&lt;/em&gt;{&lt;br/&gt; int a = arr[top];&lt;br/&gt; top--;&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; a;&lt;br/&gt; }&lt;br/&gt; }&lt;br/&gt; int peek(){&lt;br/&gt; &lt;em&gt;if&lt;/em&gt;(top != -1){&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; arr[top];&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;else&lt;/em&gt;{&lt;br/&gt; &lt;em&gt;// cout&amp;lt;&amp;lt;&amp;quot;Stack is empty&amp;quot;;&lt;/em&gt;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; 0;&lt;br/&gt; }&lt;br/&gt; };&lt;br/&gt; int priority(char &lt;em&gt;a&lt;/em&gt;){&lt;br/&gt; &lt;em&gt;if&lt;/em&gt;(&lt;em&gt;a&lt;/em&gt; == &amp;#39;+&amp;#39; || &lt;em&gt;a&lt;/em&gt; == &amp;#39;-&amp;#39;){&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; 1;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;if&lt;/em&gt;(&lt;em&gt;a&lt;/em&gt; == &amp;#39;*&amp;#39; || &lt;em&gt;a&lt;/em&gt; == &amp;#39;/&amp;#39;){&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; 2;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;if&lt;/em&gt;(&lt;em&gt;a&lt;/em&gt; == &amp;#39;^&amp;#39;){&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; 3;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;else&lt;/em&gt;{&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; -1;&lt;br/&gt; }&lt;br/&gt; }&lt;br/&gt; string convert(string &lt;em&gt;infx&lt;/em&gt;){&lt;br/&gt; int i=0;&lt;br/&gt; string pofx = &amp;quot;&amp;quot;;&lt;br/&gt; stack s;&lt;br/&gt; &lt;em&gt;while&lt;/em&gt;(&lt;em&gt;infx&lt;/em&gt;[i] != &amp;#39;\0&amp;#39;){&lt;br/&gt; &lt;em&gt;if&lt;/em&gt;(isalpha(&lt;em&gt;infx&lt;/em&gt;[i])){&lt;br/&gt; pofx += &lt;em&gt;infx&lt;/em&gt;[i];&lt;br/&gt; i++;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;else&lt;/em&gt; &lt;em&gt;if&lt;/em&gt;(&lt;em&gt;infx&lt;/em&gt;[i]==&amp;#39;(&amp;#39;){&lt;br/&gt; s.push(&lt;em&gt;infx&lt;/em&gt;[i]);&lt;br/&gt; i++;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;else&lt;/em&gt; &lt;em&gt;if&lt;/em&gt;(&lt;em&gt;infx&lt;/em&gt;[i]==&amp;#39;)&amp;#39;){&lt;br/&gt; &lt;em&gt;while&lt;/em&gt;(s.peek()!=&amp;#39;)&amp;#39;){&lt;br/&gt; pofx += s.pop();&lt;br/&gt; }&lt;br/&gt; s.pop();&lt;br/&gt; i++;&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;else&lt;/em&gt;{&lt;br/&gt; &lt;em&gt;while&lt;/em&gt;(priority(&lt;em&gt;infx&lt;/em&gt;[i]) &amp;lt;= priority(s.peek())){&lt;br/&gt; pofx += s.pop();&lt;br/&gt; }&lt;br/&gt; s.push(&lt;em&gt;infx&lt;/em&gt;[i]);&lt;br/&gt; i++;&lt;br/&gt; }&lt;br/&gt; }&lt;br/&gt; &lt;em&gt;while&lt;/em&gt;(!s.isEmpty()){&lt;br/&gt; pofx += s.pop();&lt;br/&gt; }&lt;br/&gt; cout&amp;lt;&amp;lt;&amp;quot;postfix is: &amp;quot;&amp;lt;&amp;lt;pofx; *return* pofx; } int main(){ string infix; string postfix; cout&amp;lt;&amp;lt;&amp;quot;Enter Infix form: &amp;quot;; cin&amp;gt;&amp;gt;infix;&lt;br/&gt; postfix = convert(infix);&lt;br/&gt; cout&amp;lt;&amp;lt;endl;&lt;br/&gt; &lt;em&gt;return&lt;/em&gt; 0;&lt;br/&gt; }&lt;/p&gt; &lt;p&gt;code works fine when input is without brackets but with brackets theres a constant loop of stack underflow/&lt;/p&gt; &lt;p&gt;i&amp;#39;m using wsl on vs code for compiling.&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/adityasheth&quot;&gt; /u/adityasheth &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10naaey/trying_to_make_an_infix_to_postfix_converter_but/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10naaey/trying_to_make_an_infix_to_postfix_converter_but/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10naaey</id><link href="https://www.reddit.com/r/cpp_questions/comments/10naaey/trying_to_make_an_infix_to_postfix_converter_but/" /><updated>2023-01-28T08:35:55+00:00</updated><published>2023-01-28T08:35:55+00:00</published><title>Trying to make an infix to postfix converter but it won't work with brackets.</title></entry><entry><author><name>/u/joeyjltt</name><uri>https://www.reddit.com/user/joeyjltt</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Sorry it&amp;#39;s been a while since i coded. just looking for some help&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/joeyjltt&quot;&gt; /u/joeyjltt &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n60je/can_someone_help_me_understand_what_fixed/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n60je/can_someone_help_me_understand_what_fixed/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10n60je</id><link href="https://www.reddit.com/r/cpp_questions/comments/10n60je/can_someone_help_me_understand_what_fixed/" /><updated>2023-01-28T04:24:31+00:00</updated><published>2023-01-28T04:24:31+00:00</published><title>Can someone help me understand what fixed, showpoint, and setpercision is used for</title></entry><entry><author><name>/u/HydrogenxPi</name><uri>https://www.reddit.com/user/HydrogenxPi</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;pre&gt;&lt;code&gt;constexpr long long ct_factorial(long long N) { return (N == 0) ? 1 : N * ct_factorial(N-1); } &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;or&lt;/p&gt; &lt;pre&gt;&lt;code&gt;template &amp;lt;long long N&amp;gt; constexpr long long ct_factorial() { return N * ct_factorial&amp;lt;N - 1&amp;gt;(); } template &amp;lt;&amp;gt; constexpr long long ct_factorial&amp;lt;0&amp;gt;() { return 1; } &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Thanks&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/HydrogenxPi&quot;&gt; /u/HydrogenxPi &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mxlpn/which_is_the_better_implementation_of_a_constexpr/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mxlpn/which_is_the_better_implementation_of_a_constexpr/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mxlpn</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mxlpn/which_is_the_better_implementation_of_a_constexpr/" /><updated>2023-01-27T22:08:16+00:00</updated><published>2023-01-27T22:08:16+00:00</published><title>Which is the better implementation of a constexpr factorial function?</title></entry><entry><author><name>/u/Glittering_Suit_6511</name><uri>https://www.reddit.com/user/Glittering_Suit_6511</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;As the title said I am looking for a good resources for a beginner I have looked around but I wanted other people opinion.&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Glittering_Suit_6511&quot;&gt; /u/Glittering_Suit_6511 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n6di2/what_resources_do_you_recommend_for_a_beginner/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n6di2/what_resources_do_you_recommend_for_a_beginner/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10n6di2</id><link href="https://www.reddit.com/r/cpp_questions/comments/10n6di2/what_resources_do_you_recommend_for_a_beginner/" /><updated>2023-01-28T04:43:37+00:00</updated><published>2023-01-28T04:43:37+00:00</published><title>What resources do you recommend for a beginner</title></entry><entry><author><name>/u/Tronaitor</name><uri>https://www.reddit.com/user/Tronaitor</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Hi, I am planning on making a trading engine in C++ as a personal project. I have started implementing and doing some things, but I&amp;#39;ve realised that I am not really sure what a trading engine has and how it should be implemented.&lt;/p&gt; &lt;p&gt;At the moment, I have made a basic servers (with WinSock) and I am starting to implement handling of messages usinf the FIX protocol (i.e. the client will send a message using the FIX protocol encoding, and the server will handle that message accordingly). The next thing I want to do is create an order book for the incoming orders, and excecute them to, using a matching algorithm (I&amp;#39;ll probably start with just FIFO).&lt;/p&gt; &lt;p&gt;is this what a trading engine should have, or am I missing something?&lt;/p&gt; &lt;p&gt;Thanks!&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Tronaitor&quot;&gt; /u/Tronaitor &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10msnvo/trading_engine_design/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10msnvo/trading_engine_design/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10msnvo</id><link href="https://www.reddit.com/r/cpp_questions/comments/10msnvo/trading_engine_design/" /><updated>2023-01-27T18:51:40+00:00</updated><published>2023-01-27T18:51:40+00:00</published><title>Trading Engine Design</title></entry><entry><author><name>/u/Actual-Boat-9919</name><uri>https://www.reddit.com/user/Actual-Boat-9919</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;#include &amp;lt;iostream&amp;gt;&lt;/p&gt; &lt;p&gt;#include &amp;lt;string&amp;gt;&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;using namespace std;&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;// structure to store movie information&lt;/p&gt; &lt;p&gt;struct Movie {&lt;/p&gt; &lt;p&gt;int serialNumber;&lt;/p&gt; &lt;p&gt;string name;&lt;/p&gt; &lt;p&gt;string timeFrame;&lt;/p&gt; &lt;p&gt;int seatNum = 100;&lt;/p&gt; &lt;p&gt;bool seats[100] = {false};&lt;/p&gt; &lt;p&gt;};&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;// array of movies&lt;/p&gt; &lt;p&gt;const int NUM_MOVIES = 3;&lt;/p&gt; &lt;p&gt;Movie movies[NUM_MOVIES] = {&lt;/p&gt; &lt;p&gt;{1, &amp;quot;Avengers&amp;quot;, &amp;quot;12pm - 3pm&amp;quot;},&lt;/p&gt; &lt;p&gt;{2, &amp;quot;Avatar&amp;quot;, &amp;quot;3pm - 6pm&amp;quot;},&lt;/p&gt; &lt;p&gt;{3, &amp;quot;Homealone&amp;quot;, &amp;quot;6pm - 9pm&amp;quot;}&lt;/p&gt; &lt;p&gt;};&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Actual-Boat-9919&quot;&gt; /u/Actual-Boat-9919 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n3l2l/error_could_not_convert_1_avengers_12pm_3pm_from/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n3l2l/error_could_not_convert_1_avengers_12pm_3pm_from/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10n3l2l</id><link href="https://www.reddit.com/r/cpp_questions/comments/10n3l2l/error_could_not_convert_1_avengers_12pm_3pm_from/" /><updated>2023-01-28T02:23:28+00:00</updated><published>2023-01-28T02:23:28+00:00</published><title>[Error] could not convert '{1, &quot;Avengers&quot;, &quot;12pm - 3pm&quot;}' from '&lt;brace-enclosed initializer list&gt;' to 'Movie'</title></entry><entry><author><name>/u/Beissai</name><uri>https://www.reddit.com/user/Beissai</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;I think this question must come up a lot but here we go. Ok, so, as the title says, I&amp;#39;m from and currently live here in Brazil. I&amp;#39;m not from a particularly rich part of the country like São Paulo or Rio de Janeiro: I&amp;#39;m from Ceará. We a total of 0 jobs here in C++.&lt;/p&gt; &lt;p&gt;I started a degree in Electrical Engineering and got my first contact with C, microcontrollers, microprocessors and stuff there. Unfortunately, I couldn&amp;#39;t finish my degree, but I kept studying C, C++, C#, Java and I&amp;#39;m now learning Python. Of all the languages that I learned I just fell in love with C++ due to it&amp;#39;s wide adoption in embedded systems, specifically microcontrollers. I&amp;#39;m learned how to work with PIC, AVR, STM32 in C++ as one does after getting tired from blinking a LED with Arduino.&lt;/p&gt; &lt;p&gt;I&amp;#39;m not trying to brag or anything. I&amp;#39;ve been doing this as sort of a hobby for 10 years. Mostly because I had to work at other areas to make ends meet. Unfortunately, as I said, I have no degree in engineering and even if I deed, a embedded systems development job here in my country is pretty rare and hard to come by.&lt;/p&gt; &lt;p&gt;My question is: without finding a way ($$$) to physically get out from Brazil and somehow convince a employer to give me a sponsorship (😶), is there any other way that I wold be able to persue my passion and dream of becoming a C++ embedded programmer? I&amp;#39;m just turned 31. Today. Kinda desperate. I&amp;#39;m I fucked?&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Beissai&quot;&gt; /u/Beissai &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mfehr/im_brazilian_no_degree_selftaught_c_programmer_am/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mfehr/im_brazilian_no_degree_selftaught_c_programmer_am/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mfehr</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mfehr/im_brazilian_no_degree_selftaught_c_programmer_am/" /><updated>2023-01-27T07:47:19+00:00</updated><published>2023-01-27T07:47:19+00:00</published><title>I'm brazilian. No degree. Self-taught C++ programmer. Am I fucked?</title></entry><entry><author><name>/u/better_life_please</name><uri>https://www.reddit.com/user/better_life_please</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;There&amp;#39;s a class &lt;code&gt;std::chrono::is_clock&lt;/code&gt; in the chrono header. Is there a &lt;code&gt;is_duration&amp;lt;T&amp;gt;&lt;/code&gt; in the standard library? If not then how can I implement it?&lt;/p&gt; &lt;p&gt;I want to use them in a requires expression like in:&lt;/p&gt; &lt;p&gt;&lt;code&gt;requires ( std::chrono::is_clock_v&amp;lt;C&amp;gt; &amp;amp;&amp;amp; std::chrono::is_duration_v&amp;lt;D&amp;gt; )&lt;/code&gt;&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/better_life_please&quot;&gt; /u/better_life_please &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n00u4/is_there_a_is_duration_class_in_the_library/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10n00u4/is_there_a_is_duration_class_in_the_library/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10n00u4</id><link href="https://www.reddit.com/r/cpp_questions/comments/10n00u4/is_there_a_is_duration_class_in_the_library/" /><updated>2023-01-27T23:47:29+00:00</updated><published>2023-01-27T23:47:29+00:00</published><title>Is there a is_duration class in the library?</title></entry><entry><author><name>/u/ElaborateSloth</name><uri>https://www.reddit.com/user/ElaborateSloth</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;What happens when I do this? Is the source code still embedded into the .exe but with no way to call the functions?&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/ElaborateSloth&quot;&gt; /u/ElaborateSloth &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mugvp/adding_source_file_when_compiling_without/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mugvp/adding_source_file_when_compiling_without/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mugvp</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mugvp/adding_source_file_when_compiling_without/" /><updated>2023-01-27T20:01:11+00:00</updated><published>2023-01-27T20:01:11+00:00</published><title>Adding source file when compiling without including header file</title></entry><entry><author><name>/u/Kitchen_Discipline_1</name><uri>https://www.reddit.com/user/Kitchen_Discipline_1</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Why can&amp;#39;t we have our own ostream object if cout is an object of ostream class?&lt;/p&gt; &lt;p&gt;I&amp;#39;m trying to achieve the below, but it&amp;#39;s not working. Any advice on this ?&lt;/p&gt; &lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt; using namespace std; template &amp;lt;typename T&amp;gt; // Second argument must be template argument ostream&amp;amp; operator&amp;lt;&amp;lt;(ostream&amp;amp; out, T const&amp;amp; result) { out &amp;lt;&amp;lt; &amp;quot;overloading&amp;quot; &amp;lt;&amp;lt; result &amp;lt;&amp;lt; &amp;quot;done&amp;quot;; return out; } int main() { // os should have the type ostream&amp;amp; ostream&amp;amp; os = std::cout; os &amp;lt;&amp;lt; &amp;quot;Hello World&amp;quot;; } &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Link to godbolt - &lt;a href=&quot;https://godbolt.org/z/eo6Woz961&quot;&gt;https://godbolt.org/z/eo6Woz961&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Kitchen_Discipline_1&quot;&gt; /u/Kitchen_Discipline_1 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mmej1/operator_ostream_t_const_not_working/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mmej1/operator_ostream_t_const_not_working/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mmej1</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mmej1/operator_ostream_t_const_not_working/" /><updated>2023-01-27T14:39:10+00:00</updated><published>2023-01-27T14:39:10+00:00</published><title>operator&lt;&lt; (ostream&amp; , T const&amp;) - not working</title></entry><entry><author><name>/u/AppropriateCinnamon</name><uri>https://www.reddit.com/user/AppropriateCinnamon</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;I often times find myself having to loosely couple components at work through the observer pattern, where some set of callbacks (e.g. a vector of std::function with some signature) is registered on an object and each callback gets called in a certain scenario.&lt;/p&gt; &lt;p&gt;This can also get more complicated when the callbacks are decoupled via some &amp;quot;command queue&amp;quot; on a separate thread.&lt;/p&gt; &lt;p&gt;I have written this pattern many times, but I don&amp;#39;t think I&amp;#39;m doing it well.&lt;/p&gt; &lt;p&gt;I&amp;#39;ve seen this done with Boost::Asio, but I can&amp;#39;t always bring this into my dependencies at work. If this is the correct answer, then please let me know!&lt;/p&gt; &lt;p&gt;Are there libraries, patterns, or books/resources that do this &amp;quot;observer queue across multiple threads&amp;quot; pattern?&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/AppropriateCinnamon&quot;&gt; /u/AppropriateCinnamon &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mx37m/callback_queue_pattern_library_suggestions/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mx37m/callback_queue_pattern_library_suggestions/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mx37m</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mx37m/callback_queue_pattern_library_suggestions/" /><updated>2023-01-27T21:47:35+00:00</updated><published>2023-01-27T21:47:35+00:00</published><title>callback queue pattern / library suggestions</title></entry><entry><author><name>/u/Call_Me_Madu</name><uri>https://www.reddit.com/user/Call_Me_Madu</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;So i have tried this code that basically takes an input for a number, checks if the number is either odd or even , if its even it divides the number by 2 , if the number is odd it multiplies it by 3 and then adds 1, so . But when i run it it only just takes an input number and the program ends, can anyone explain why?&lt;/p&gt; &lt;p&gt;heres the code:&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;#include &amp;lt;iostream&amp;gt;&lt;/p&gt; &lt;p&gt;using namespace std;&lt;/p&gt; &lt;p&gt;int main()&lt;/p&gt; &lt;p&gt;{&lt;/p&gt; &lt;p&gt;/* program that does the collatz conjecture&lt;/p&gt; &lt;p&gt;if num is odd num= (num*3)+1&lt;/p&gt; &lt;p&gt;else num will be divided by 2&lt;/p&gt; &lt;p&gt;*/&lt;/p&gt; &lt;p&gt;int num;&lt;/p&gt; &lt;p&gt;cout &amp;lt;&amp;lt;&amp;quot;Enter a number that isn&amp;#39;t equal to one&amp;quot;&amp;lt;&amp;lt; endl;&lt;/p&gt; &lt;p&gt;cin &amp;gt;&amp;gt; num;&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;for(int i=0; i&amp;lt;500; i++)&lt;/p&gt; &lt;p&gt;{ while(num !=1)&lt;/p&gt; &lt;p&gt;{ if (num % 2 == 0 )&lt;/p&gt; &lt;p&gt;{ num = (num*3)+1;&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;p&gt;else if (num % 2 == 1)&lt;/p&gt; &lt;p&gt;{ num = num/2;&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;p&gt;return num;&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;p&gt;return 0;&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Call_Me_Madu&quot;&gt; /u/Call_Me_Madu &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mvyad/program_doesnt_work/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mvyad/program_doesnt_work/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mvyad</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mvyad/program_doesnt_work/" /><updated>2023-01-27T21:01:40+00:00</updated><published>2023-01-27T21:01:40+00:00</published><title>Program doesn't work</title></entry><entry><author><name>/u/Kitchen_Discipline_1</name><uri>https://www.reddit.com/user/Kitchen_Discipline_1</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Accessing std::string and std::ostream in destructor throws an error &amp;quot;&lt;strong&gt;error: an exception may be thrown in function &amp;#39;~Name&amp;#39; which should not throw exceptions&lt;/strong&gt;&amp;quot; in Visual Studio, Why is it so?&lt;/p&gt; &lt;p&gt;However, accessing bool variable is permitted. C++ version is 17&lt;/p&gt; &lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt; #include &amp;lt;string&amp;gt; using namespace std; class Name { public: Name(std::string n) : str(n), os(std::cout) {} //The below line throws this error in VS //error: an exception may be thrown in //function &amp;#39;~Name&amp;#39; which should not //throw exceptions ~Name() { std::cout &amp;lt;&amp;lt; str; os &amp;lt;&amp;lt; &amp;quot; world&amp;quot;; } private: std::string str; std::ostream&amp;amp; os; }; int main() { Name n(&amp;quot;hello&amp;quot;); return 0; } &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Godbolt link is here: &lt;a href=&quot;https://godbolt.org/z/97YsvT4qd&quot;&gt;https://godbolt.org/z/97YsvT4qd&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Kitchen_Discipline_1&quot;&gt; /u/Kitchen_Discipline_1 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mu92b/cant_we_access_stdstring_variable_in_the/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mu92b/cant_we_access_stdstring_variable_in_the/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mu92b</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mu92b/cant_we_access_stdstring_variable_in_the/" /><updated>2023-01-27T19:52:46+00:00</updated><published>2023-01-27T19:52:46+00:00</published><title>Can't we access std::string variable in the destructor ?</title></entry><entry><author><name>/u/IllPersonality356</name><uri>https://www.reddit.com/user/IllPersonality356</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Hello, I am working on a C++ project and I am getting the error not point to a block of non-zero sizeMaxineJones. when trying to get an output from my program. I am using Microsoft Visual Studio Community. Here is the program : &lt;/p&gt; &lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt; #include &amp;lt;string&amp;gt; using namespace std; const string FIRST_NAME = &amp;quot;Maxine&amp;quot;; const string LAST_NAME = &amp;quot;Jones&amp;quot;; int main() { string message; string name; name = FIRST_NAME + LAST_NAME; message = &amp;quot;Good Morning&amp;quot; + &amp;#39; &amp;#39; + name + &amp;#39;.&amp;#39;; cout &amp;lt;&amp;lt; message &amp;lt;&amp;lt; endl; return 0; } &lt;/code&gt;&lt;/pre&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/IllPersonality356&quot;&gt; /u/IllPersonality356 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mtt5v/not_point_to_a_block_of_nonzero_size/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mtt5v/not_point_to_a_block_of_nonzero_size/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mtt5v</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mtt5v/not_point_to_a_block_of_nonzero_size/" /><updated>2023-01-27T19:35:15+00:00</updated><published>2023-01-27T19:35:15+00:00</published><title>not point to a block of non-zero size</title></entry><entry><author><name>/u/Tony942316</name><uri>https://www.reddit.com/user/Tony942316</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;I&amp;#39;ve been learning about move semantics (and other things) from Effective Modern C++ by Scott Meyers and I&amp;#39;ve been trying to apply some of the things I&amp;#39;ve read about. In particular I&amp;#39;ve been trying to reduce the number of move and copy constructor calls as much as possible. Which leads to me this behavior I found, given a class defined as such: ```c++ class foo { private: int* x; size_t size; public: foo() : x(nullptr), size(100&amp;#39;000ull) { std::cout &amp;lt;&amp;lt; &amp;quot;Default\n&amp;quot;; x = new int[size]; } foo(size_t s) : x(nullptr), size(s) { std::cout &amp;lt;&amp;lt; &amp;quot;Param\n&amp;quot;; x = new int[size]; } ~foo() { std::cout &amp;lt;&amp;lt; &amp;quot;Destruct\n&amp;quot;; delete[] x; } foo(const foo&amp;amp; other) : x(nullptr), size(other.size) { std::cout &amp;lt;&amp;lt; &amp;quot;Copy\n&amp;quot;; x = new int[size]; std::memcpy(x, other.x, size); } foo(foo&amp;amp;&amp;amp; other) noexcept : x(other.x), size(other.size) { std::cout &amp;lt;&amp;lt; &amp;quot;Move\n&amp;quot;; other.x = nullptr; other.size = 0ull; }&lt;/p&gt; &lt;pre&gt;&lt;code&gt;// assignment operators similarly defined but never called so they are omitted &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;}; ```&lt;/p&gt; &lt;p&gt;Again the goal is to call the copy and move constructors as little as possible. So given this main function:&lt;/p&gt; &lt;p&gt;```c++ int main() { std::cout &amp;lt;&amp;lt; &amp;quot;Start\n\n&amp;quot;;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;std::vector&amp;lt;foo&amp;gt; fooVec1{ 10ull, 10ull, 10ull, 10ull }; std::cout &amp;lt;&amp;lt; &amp;quot;**********\n&amp;quot;; std::cin.get(); std::vector&amp;lt;foo&amp;gt; fooVec2; fooVec2.reserve(4); fooVec2.emplace_back(10ull); fooVec2.emplace_back(10ull); fooVec2.emplace_back(10ull); fooVec2.emplace_back(10ull); std::cout &amp;lt;&amp;lt; &amp;quot;**********\n&amp;quot;; std::cin.get(); std::cout &amp;lt;&amp;lt; &amp;quot;\n\nEnd&amp;quot; &amp;lt;&amp;lt; std::endl; std::cin.get(); return 0; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;} ```&lt;/p&gt; &lt;p&gt;I find that the construction of fooVec1 creates 4 temporary foo objects, copies them and then destroys the copies while fooVec2 doesn&amp;#39;t create any copies at all (ideal?). The output produced is as follows:&lt;/p&gt; &lt;p&gt;``` Param // dummy objects created Param Param Param Copy // dummy objects copied Copy Copy Coyy Destruct // dummy objects destroyed Destruct Destruct Destruct&lt;/p&gt; &lt;hr/&gt; &lt;p&gt;Param // objects created in place Param Param Param&lt;/p&gt; &lt;hr/&gt; &lt;p&gt;End&lt;/p&gt; &lt;p&gt;Destruct // all objects destroyed Destruct Destruct Destruct Destruct Destruct Destruct Destruct ```&lt;/p&gt; &lt;p&gt;My question is how can I get the functionality of fooVec2 but during the initialization? I wrote a simple function to emulate the desired behavior, but I&amp;#39;m looking for a standard function or initiation pattern that already exists in the language.&lt;/p&gt; &lt;p&gt;&lt;code&gt;c++ void initContainer(std::vector&amp;lt;foo&amp;gt;&amp;amp; container, std::initializer_list&amp;lt;size_t&amp;gt;&amp;amp;&amp;amp; vals) { container.reserve(vals.size()); for (auto&amp;amp; val : vals) { container.emplace_back(val); } } &lt;/code&gt;&lt;/p&gt; &lt;p&gt;edit: This post is kind of long and verbose, any tips to reduce the size or make it easier to read are welcome&lt;/p&gt; &lt;p&gt;edit2: Also why is fooVec1 copying the objects instead of moving them?&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Tony942316&quot;&gt; /u/Tony942316 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mqzwc/stdvector_construction/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mqzwc/stdvector_construction/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mqzwc</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mqzwc/stdvector_construction/" /><updated>2023-01-27T17:46:02+00:00</updated><published>2023-01-27T17:46:02+00:00</published><title>std::vector construction</title></entry><entry><author><name>/u/Beosar</name><uri>https://www.reddit.com/user/Beosar</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Two questions:&lt;/p&gt; &lt;p&gt;1) My network code that I wrote many years ago does this:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;#define MAXBUF 65536 unsigned char buffer[MAXBUF]; sockaddr_in6 from; socklen_t fromLength = sizeof(sockaddr_in6); int RecvStatus = recvfrom(UDPSocket, (char*)buffer, MAXBUF, 0, (sockaddr*)&amp;amp;from, &amp;amp;fromLength); &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;It works like a charm but is that actually valid? I mean, I&amp;#39;m supposed to use sockaddr_in6 for IPv6 and recvfrom takes a sockaddr* parameter. If that&amp;#39;s not valid C++, how would you do that correctly?&lt;/p&gt; &lt;p&gt;2) Can I save pointers to string literals? Something like this:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;const std::array&amp;lt;const char*, 2&amp;gt; addresses = {&amp;quot;localhost&amp;quot;, &amp;quot;255.255.255.255&amp;quot;}; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;As far as I know they are saved in the data section of the program and should stay valid, but can I rely on that?&lt;/p&gt; &lt;p&gt;Edit: Found the answer to the second question myself:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;String literals have static storage duration, and thus exist in memory for the life of the program. &lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;&lt;a href=&quot;https://en.cppreference.com/w/cpp/language/string_literal&quot;&gt;https://en.cppreference.com/w/cpp/language/string_literal&lt;/a&gt;&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Beosar&quot;&gt; /u/Beosar &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mlfzn/am_i_allowed_to_do_that/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mlfzn/am_i_allowed_to_do_that/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mlfzn</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mlfzn/am_i_allowed_to_do_that/" /><updated>2023-01-27T13:57:28+00:00</updated><published>2023-01-27T13:57:28+00:00</published><title>Am I allowed to do that?</title></entry><entry><author><name>/u/docperianFB27</name><uri>https://www.reddit.com/user/docperianFB27</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Hey everybody! I&amp;#39;m currently working on a project, which requires directly working with bytes. I read an input from a file and then should work with it as with sequence of bits. Currently I am reading it into a char vector. But it&amp;#39;s not very clean. How should I represent a bitstream? &lt;/p&gt; &lt;p&gt;There is a &amp;quot;bitset&amp;quot; type in the standard library, but it needs to know the size at the compile time. And that&amp;#39;s not my case. &lt;/p&gt; &lt;p&gt;I have a few options: using a bool vector (looks kinda like a crutch); continue working with char vector (I don&amp;#39;t really like representing bytes as chars, and it&amp;#39;s not clean as I&amp;#39;ve said); I can change char to std::byte, it seems like a more natural data type for what I&amp;#39;m doing. Which one should I go with?&lt;/p&gt; &lt;p&gt;And another question. It&amp;#39;s said, that bit shift to the left e. g. 01110000 &amp;lt;&amp;lt; 2 causes UB. Is it still bad to do this if I know, what I&amp;#39;m doing?&lt;/p&gt; &lt;p&gt;UPD: right now I am using an &amp;quot;unsigned char&amp;quot; not the signed one&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/docperianFB27&quot;&gt; /u/docperianFB27 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10ml02p/working_with_bitstreams_the_best_type_to/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10ml02p/working_with_bitstreams_the_best_type_to/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10ml02p</id><link href="https://www.reddit.com/r/cpp_questions/comments/10ml02p/working_with_bitstreams_the_best_type_to/" /><updated>2023-01-27T13:37:30+00:00</updated><published>2023-01-27T13:37:30+00:00</published><title>Working with bitstreams. The best type to represent bits</title></entry><entry><author><name>/u/dogmasucks</name><uri>https://www.reddit.com/user/dogmasucks</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Hey all,&lt;/p&gt; &lt;p&gt;I&amp;#39;m interested in learning about networking in depth, specifically building API requests and websockets from scratch using C/C++. Can anyone recommend any books or resources that cover the basics and gradually build upon that knowledge? I&amp;#39;m looking for something that will take me from a beginner level to an advanced level.&lt;/p&gt; &lt;p&gt;Thanks in advance for any recommendations!&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/dogmasucks&quot;&gt; /u/dogmasucks &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10lw7ad/learning_to_build_networking_applications_using/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10lw7ad/learning_to_build_networking_applications_using/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10lw7ad</id><link href="https://www.reddit.com/r/cpp_questions/comments/10lw7ad/learning_to_build_networking_applications_using/" /><updated>2023-01-26T16:43:22+00:00</updated><published>2023-01-26T16:43:22+00:00</published><title>Learning to build networking applications using C/C++ from scratch</title></entry><entry><author><name>/u/SogaBan</name><uri>https://www.reddit.com/user/SogaBan</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Scott Meyers, in his Effective C++, in item #3 discusses about const correctness&lt;/em&gt;&lt;/strong&gt;. In doing so he demonstrates an example like this:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;class textBlock { string text; public: foo(string in = &amp;quot;&amp;quot;):text{in}{} const char&amp;amp; operator[](size_t pos) const { return text[pos]; } char&amp;amp; operator[](size_t pos) { return const_cast&amp;lt;char&amp;amp;&amp;gt;(static_cast&amp;lt;const foo&amp;amp;&amp;gt;(*this)[pos]); } }; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;He emphasises that to avoid code duplications and for the ease of maintainability - it&amp;#39;s preferred to express any non-const function(s) in terms of const version of the same function.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;My question:&lt;/strong&gt; Is it okay if I do it the other way? This is the equivalent code :&lt;/p&gt; &lt;pre&gt;&lt;code&gt;class textBlock { string text; public: foo(string in = &amp;quot;&amp;quot;):text{in}{} const char&amp;amp; operator[](size_t pos) const { return const_cast&amp;lt;textBlock&amp;amp;&amp;gt;(*this)[pos]; } char&amp;amp; operator[](size_t pos) { return text[pos]; } }; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&lt;strong&gt;What are the pros and cons of each&lt;/strong&gt; ? Also, what does the C++ standard protocols (if any) say about it?&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/SogaBan&quot;&gt; /u/SogaBan &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10m67e6/clarification_of_const_correctness/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10m67e6/clarification_of_const_correctness/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10m67e6</id><link href="https://www.reddit.com/r/cpp_questions/comments/10m67e6/clarification_of_const_correctness/" /><updated>2023-01-26T23:41:31+00:00</updated><published>2023-01-26T23:41:31+00:00</published><title>Clarification of const correctness</title></entry><entry><author><name>/u/ElaborateSloth</name><uri>https://www.reddit.com/user/ElaborateSloth</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;I am working on a component based game editor, and would like to have all available classes in a dropdown list to place in the world. The problem is where this list is supposed to fetch all available classes.&lt;/p&gt; &lt;p&gt;One method I have looked into is creating an std::map with a string key, and the content of the map to be a lambda function that creates and returns a specified object. Every time a new class is created, one would have to add this class to the map with the name of the class and a lambda function with its creation. Once the editor starts, it iterates through the map and populates the list with names. When a name is clicked and placed in editor, the lambda function is called.&lt;/p&gt; &lt;p&gt;All objects would inherit from class Component, which means only component generic constructor parameters can be accessed, like the component position and perhaps its parent components.&lt;/p&gt; &lt;p&gt;Something to take into account is that the source files with classes are shared with one program called Player and another called Editor. One is for creating the game and serializing it to a file. The other is to simply run this file. &lt;/p&gt; &lt;p&gt;Adding classes to a list sounds a little tedious though. Is there perhaps a way to use macros?&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/ElaborateSloth&quot;&gt; /u/ElaborateSloth &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mhbuv/detecting_all_classes_in_a_source_file/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mhbuv/detecting_all_classes_in_a_source_file/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mhbuv</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mhbuv/detecting_all_classes_in_a_source_file/" /><updated>2023-01-27T10:02:55+00:00</updated><published>2023-01-27T10:02:55+00:00</published><title>Detecting all classes in a source file</title></entry><entry><author><name>/u/whyvitamins</name><uri>https://www.reddit.com/user/whyvitamins</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;is there some mechanism in c++ templates which defines what the generic type can actually do? for example, many tutorials use templates as a way to create a function which can sum two numbers (ints, floats, etc)&lt;/p&gt; &lt;p&gt;however, how do we know that those types can actually be added together? what if we pass in a string? or a custom type? there isn&amp;#39;t a mechanism defining the operation of summation for those&lt;/p&gt; &lt;p&gt;for example, in rust there are traits, which bind the generic type to only those types which have this trait implemented, meaning if we wanted to implement such an generic addition function, which could just bind the generic parameter &lt;code&gt;T&lt;/code&gt; with a trait &lt;code&gt;std::ops::Add&lt;/code&gt;&lt;/p&gt; &lt;p&gt;i guess i&amp;#39;m looking for something similar in c++ or whatever alternative mechanism is used...&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/whyvitamins&quot;&gt; /u/whyvitamins &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10maid9/template_specificity_mechanism/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10maid9/template_specificity_mechanism/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10maid9</id><link href="https://www.reddit.com/r/cpp_questions/comments/10maid9/template_specificity_mechanism/" /><updated>2023-01-27T03:08:55+00:00</updated><published>2023-01-27T03:08:55+00:00</published><title>Template specificity mechanism</title></entry><entry><author><name>/u/Dapper-Equipment5142</name><uri>https://www.reddit.com/user/Dapper-Equipment5142</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;Hi, i am studying to become a software developer.&lt;/p&gt; &lt;p&gt;I got a function that i need help understanding. If in function A there is an int that gets given the value 5, why does the int in function B which i dont give a value, get given the value 5?&lt;/p&gt; &lt;p&gt;Thanks for any help! :D&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/Dapper-Equipment5142&quot;&gt; /u/Dapper-Equipment5142 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mftom/mind_reading/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mftom/mind_reading/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mftom</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mftom/mind_reading/" /><updated>2023-01-27T08:16:02+00:00</updated><published>2023-01-27T08:16:02+00:00</published><title>Mind reading</title></entry><entry><author><name>/u/OccasionCrazy7937</name><uri>https://www.reddit.com/user/OccasionCrazy7937</uri></author><category term="cpp_questions" label="r/cpp_questions"/><content type="html">&lt;!-- SC_OFF --&gt;&lt;div class=&quot;md&quot;&gt;&lt;p&gt;hi im in hs doing cs and this is the hw that I&amp;#39;m struggling with atm, i keep getting errors&lt;/p&gt; &lt;p&gt;i would really appreciate any help.&lt;/p&gt; &lt;p&gt;Write a program to display all odd numbers between 0 and 200.&lt;/p&gt; &lt;p&gt;then allow the user to input where to start from and where to stop. user should also be able to specify whether they want odd or even numbers to be shown &lt;/p&gt; &lt;p&gt;this is what i have done but i keep getting errors&lt;/p&gt; &lt;p&gt;#include&amp;lt;iostream&amp;gt;&lt;/p&gt; &lt;p&gt;#include &amp;lt;string&amp;gt;&lt;/p&gt; &lt;p&gt;using namespace std;&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;int main()&lt;/p&gt; &lt;p&gt;{&lt;/p&gt; &lt;pre&gt;&lt;code&gt;int number, w = 1; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;cout &amp;lt;&amp;lt; &amp;quot;\\nEnter Maximum limit Value so you can print Odd Numbers = &amp;quot;; cin &amp;gt;&amp;gt; number; cout &amp;lt;&amp;lt; &amp;quot;\\nList of Odd Numbers from 1 to &amp;quot; &amp;lt;&amp;lt; number &amp;lt;&amp;lt; &amp;quot; are\\n&amp;quot;; while ( w &amp;lt;= number) { cout &amp;lt;&amp;lt;w &amp;lt;&amp;lt; &amp;quot; &amp;quot;; w = w + 2; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;} return 0; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;}&lt;/p&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;p&gt;main()&lt;/p&gt; &lt;p&gt;{&lt;/p&gt; &lt;pre&gt;&lt;code&gt;int number=0, w=1 &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;{ string input; cout &amp;lt;&amp;lt; &amp;quot;\\n do you want even numbers?,say yes or no&amp;quot; &amp;lt;&amp;lt; endl; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&amp;#x200B;&lt;/p&gt; &lt;pre&gt;&lt;code&gt; cin &amp;gt;&amp;gt; input; cout &amp;lt;&amp;lt; &amp;quot;\\nList of even Numbers from 1 to &amp;quot; &amp;lt;&amp;lt; numbers &amp;lt;&amp;lt; &amp;quot; are\\n&amp;quot;; while (w &amp;lt;= number) cout &amp;lt;&amp;lt; w &amp;lt;&amp;lt; &amp;quot; &amp;quot;; w = w + 1; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;}&lt;/p&gt; &lt;pre&gt;&lt;code&gt;return 0; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;}&lt;/p&gt; &lt;p&gt;any help is really appreciated thanks!&lt;/p&gt; &lt;/div&gt;&lt;!-- SC_ON --&gt; &amp;#32; submitted by &amp;#32; &lt;a href=&quot;https://www.reddit.com/user/OccasionCrazy7937&quot;&gt; /u/OccasionCrazy7937 &lt;/a&gt; &lt;br/&gt; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mbqn8/hi_i_need_help_creating_a_program_to_create_a_odd/&quot;&gt;[link]&lt;/a&gt;&lt;/span&gt; &amp;#32; &lt;span&gt;&lt;a href=&quot;https://www.reddit.com/r/cpp_questions/comments/10mbqn8/hi_i_need_help_creating_a_program_to_create_a_odd/&quot;&gt;[comments]&lt;/a&gt;&lt;/span&gt;</content><id>t3_10mbqn8</id><link href="https://www.reddit.com/r/cpp_questions/comments/10mbqn8/hi_i_need_help_creating_a_program_to_create_a_odd/" /><updated>2023-01-27T04:11:07+00:00</updated><published>2023-01-27T04:11:07+00:00</published><title>hi i need help creating a program to create a odd and even program</title></entry></feed>