<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>C Board - C++ Programming</title>
		<link>http://cboard.cprogramming.com/</link>
		<description>Questions specific to C++ Programming</description>
		<language>en</language>
		<lastBuildDate>Fri, 24 May 2013 17:44:26 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://cboard.cprogramming.com/images/misc/rss.png</url>
			<title>C Board - C++ Programming</title>
			<link>http://cboard.cprogramming.com/</link>
		</image>
		<item>
			<title>Overlapping squares</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156991-overlapping-squares.html</link>
			<pubDate>Fri, 24 May 2013 17:28:58 GMT</pubDate>
			<description>How would i calculate a surface that up to 10^5 squares cover. The info you get is xpos,ypos and width for each square. How would you calculate the total surface covered (if any overlap only one counts). 
Cannot use a big array of bools as the memory limit is 512 MiB.</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->How would i calculate a surface that up to 10^5 squares cover. The info you get is xpos,ypos and width for each square. How would you calculate the total surface covered (if any overlap only one counts).<br />
Cannot use a big array of bools as the memory limit is 512 MiB.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>Tobias Mihel</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156991-overlapping-squares.html</guid>
		</item>
		<item>
			<title><![CDATA[[Help] Mysterious Numbers]]></title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156989-%5Bhelp%5D-mysterious-numbers.html</link>
			<pubDate>Fri, 24 May 2013 14:38:52 GMT</pubDate>
			<description><![CDATA[Hello! 
 
I am new here, and created an account to ask for some help. Long story short: haven't touched C++ since High School, and need some help with a problem. I stupidly offered a girl some help and am a little stuck in making this work. 
 
A number is "mysterious" if it can be properly divided...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hello!<br />
<br />
I am new here, and created an account to ask for some help. Long story short: haven't touched C++ since High School, and need some help with a problem. I stupidly offered a girl some help and am a little stuck in making this work.<br />
<br />
A number is &quot;mysterious&quot; if it can be properly divided by the number of factors it has. For ex.: 9 has 3 factors, and is divisible by 3. 12 has 6 factors and is divisible by 6.<br />
<br />
I want to input a range and have it output the number of mysterious numbers within it. As soon as I enter the second number, my program closes though. Am I anywhere near my goal?<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;iostream&gt;using namespace std;<br />
<br />
<br />
bool esMisterioso(int n)<br />
{<br />
&nbsp; &nbsp; bool esMisterioso = false;<br />
&nbsp; &nbsp; int c = 0;<br />
&nbsp; &nbsp; for ( int i = 1; i &lt;= n; i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ( n % i == 0 ) c++;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; if ( n % c == 0 ) esMisterioso = true;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; return esMisterioso;<br />
}<br />
<br />
<br />
int main()<br />
{<br />
&nbsp; &nbsp; int a, b, num = 0;<br />
&nbsp; &nbsp; cin &gt;&gt; a &gt;&gt; b;<br />
&nbsp; &nbsp; for ( int i = a; i &lt;= b; i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ( esMisterioso(i) ) num++;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; cout &lt;&lt; num;<br />
&nbsp; &nbsp; return 0;<br />
}</code><hr />
</div><!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>alejavierp</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156989-%5Bhelp%5D-mysterious-numbers.html</guid>
		</item>
		<item>
			<title>Memory failures in C++ maps</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156981-memory-failures-cplusplus-maps.html</link>
			<pubDate>Fri, 24 May 2013 03:20:17 GMT</pubDate>
			<description>I noticed that there is a certain danger when we use the C++ maps to look up a key that was missing. When a missing key is looked up from a map, this actually affects the size() of the map, leading to unexpected secondary bugs when this map is later used again. 
 
Here is a test code and its output...</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->I noticed that there is a certain danger when we use the C++ maps to look up a key that was missing. When a missing key is looked up from a map, this actually affects the size() of the map, leading to unexpected secondary bugs when this map is later used again.<br />
<br />
Here is a test code and its output to visualize what is going on:<br />
<br />
<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><br />
#include &lt;stdio.h&gt;&nbsp; &nbsp; &nbsp; <br />
#include &lt;stdlib.h&gt;&nbsp; <br />
#include &lt;iomanip&gt;<br />
#include &lt;fstream&gt;<br />
#include &lt;iostream&gt;<br />
&nbsp;#include &lt;cstring&gt;<br />
#include &lt;sstream&gt;<br />
#include &lt;string&gt;<br />
#include &lt;string.h&gt;<br />
<br />
<br />
#include &lt;vector&gt;<br />
#include &lt;map&gt;<br />
<br />
<br />
using namespace std;<br />
<br />
<br />
<br />
<br />
map&lt;string, int&gt; testMap;<br />
<br />
<br />
int main()<br />
{&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
<br />
<br />
&nbsp; &nbsp; testMap[&quot;a&quot;]=4;<br />
&nbsp; &nbsp; testMap[&quot;b&quot;]=5;<br />
&nbsp; &nbsp; testMap[&quot;c&quot;]=6;<br />
&nbsp; &nbsp; testMap[&quot;d&quot;]=7;<br />
&nbsp; &nbsp; testMap[&quot;e&quot;]=8;<br />
&nbsp; &nbsp; testMap[&quot;f&quot;]=9;<br />
&nbsp; &nbsp; testMap[&quot;g&quot;]=10;<br />
&nbsp; &nbsp; testMap[&quot;h&quot;]=11;<br />
&nbsp; &nbsp; testMap[&quot;k&quot;]=12;<br />
&nbsp; &nbsp; testMap[&quot;l&quot;]=13;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; vector&lt;string&gt; vec_st;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; vec_st.push_back(&quot;a&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;b&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;c&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;d&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;e&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;f&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;g&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;h&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;k&quot;);<br />
&nbsp; &nbsp; vec_st.push_back(&quot;l&quot;);<br />
<br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; int firstSize = testMap.size();<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;Before the search for missing key m, we have testMap.size() = &quot; &lt;&lt; firstSize &lt;&lt; endl;<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;Values of the map before the attempt to look up missing key: &quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; for(int i=0; i &lt; testMap.size(); i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;testMap[vec_st[&quot;&lt;&lt;i&lt;&lt;&quot;] ] = &quot; &lt;&lt; testMap[vec_st[i] ] &lt;&lt; endl;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; string s = &quot;m&quot;;<br />
&nbsp; &nbsp; int j2 = testMap[s] ; // Questionable attempt to find a missing key's value<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;s = &quot; &lt;&lt; s &lt;&lt; &quot; , but after this questionable lookup of s, we get testMap[s] = &quot; &lt;&lt; j2 &lt;&lt; endl;<br />
<br />
<br />
&nbsp; &nbsp; int secondSize = testMap.size();<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;Size AFTER the search for missing key m = &quot; &lt;&lt; secondSize &lt;&lt; endl;<br />
&nbsp; &nbsp; cout &lt;&lt; &quot; After the attempt to look up a missing key we get: &quot; &lt;&lt; endl;<br />
<br />
<br />
&nbsp; &nbsp; for(int i=0; i&lt; testMap.size(); i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;testMap[vec_st[&quot;&lt;&lt;i&lt;&lt;&quot;] ] = &quot; &lt;&lt; testMap[vec_st[i] ]&lt;&lt; endl;<br />
&nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; // Better safeguard: use the ::count() function to check that the key exists in the first place:<br />
&nbsp; &nbsp; // Write: if(testMap.count(s) &gt;0) { j2=testMap[s] ; }<br />
&nbsp; &nbsp; <br />
<br />
<br />
}</code><hr />
</div><u>Here is the output that shows that the attempt to look up a missing key results in the alteration of the size of the map, an alteration of the memory:<br />
</u><br />
Before the search for missing key m, we have testMap.size() = <b><font color="#ff0000">10</font></b><br />
Values of the map before the attempt to look up missing key: <br />
testMap[vec_st[0] ] = 4<br />
testMap[vec_st[1] ] = 5<br />
testMap[vec_st[2] ] = 6<br />
testMap[vec_st[3] ] = 7<br />
testMap[vec_st[4] ] = 8<br />
testMap[vec_st[5] ] = 9<br />
testMap[vec_st[6] ] = 10<br />
testMap[vec_st[7] ] = 11<br />
testMap[vec_st[8] ] = 12<br />
testMap[vec_st[9] ] = 13<br />
s = m , but after this questionable lookup of s, we get testMap[s] = 0<br />
Size AFTER the search for missing key m = <b><font color="#ff0000">11</font></b><br />
 After the attempt to look up a missing key we get: <br />
testMap[vec_st[0] ] = 4<br />
testMap[vec_st[1] ] = 5<br />
testMap[vec_st[2] ] = 6<br />
testMap[vec_st[3] ] = 7<br />
testMap[vec_st[4] ] = 8<br />
testMap[vec_st[5] ] = 9<br />
testMap[vec_st[6] ] = 10<br />
testMap[vec_st[7] ] = 11<br />
testMap[vec_st[8] ] = 12<br />
testMap[vec_st[9] ] = 13<br />
Segmentation fault (core dumped)<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>FortranLevelC++</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156981-memory-failures-cplusplus-maps.html</guid>
		</item>
		<item>
			<title>Cannot push_back  string at the end of vector</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156979-cannot-push_back-string-end-vector.html</link>
			<pubDate>Fri, 24 May 2013 02:54:44 GMT</pubDate>
			<description>Hi 
 
I have below classes 
 
Code: 
--------- 
class moClassValueContainer { 
public: 
	moClassValueContainer(); 
	moClassValueContainer(string,int);</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi<br />
<br />
I have below classes<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">class moClassValueContainer {<br />
public:<br />
&nbsp; &nbsp; &nbsp; &nbsp; moClassValueContainer();<br />
&nbsp; &nbsp; &nbsp; &nbsp; moClassValueContainer(string,int);<br />
&nbsp; &nbsp; &nbsp; &nbsp; string&nbsp; &nbsp; &nbsp; &nbsp; name;<br />
&nbsp; &nbsp; &nbsp; &nbsp; int&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxNodeCount;<br />
&nbsp; &nbsp; &nbsp; &nbsp; vector&lt;string&gt; headerFields;<br />
};<br />
typedef enum {SINGLE,LIST} valueType; // this is C style<br />
class Container {<br />
&nbsp; &nbsp; &nbsp; &nbsp; public:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Container (xml_node n);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueType getType() { return type; }&nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vector&lt; vector&lt;string&gt; &gt; getListNames();&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vector&lt; vector&lt;string&gt; &gt; getListValues();&nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string getListElement(string n);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string getName();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string getValue();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int getElementCount();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; private:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueType type;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xml_node node;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int count;&nbsp; &nbsp; &nbsp; // for list only, otherwise count = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int itemNo;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string name;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string moClass;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vector&lt; vector&lt;string&gt; &gt; listNames;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vector&lt; vector&lt;string&gt; &gt; listValues;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void analyseList();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bool listAnalyzed;<br />
};<br />
<br />
Container::Container(xml_node n) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; node = n;<br />
&nbsp; &nbsp; &nbsp; &nbsp; itemNo = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; listAnalyzed = false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; name = string(node.attribute(&quot;name&quot;).value());<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (!string(node.name()).compare(&quot;list&quot;)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type = LIST;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp;  } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type = SINGLE;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count = 1;<br />
&nbsp; &nbsp; &nbsp; &nbsp;  }<br />
}<br />
<br />
string Container::getName() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (type == SINGLE)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return name;<br />
&nbsp; &nbsp; &nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &quot;&quot;;<br />
}</code><hr />
</div>In my main.cpp, I have blow loop<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><br />
for (xml_node tnode = it-&gt;first_child(); tnode ; tnode = tnode.next_sibling()) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; Container tmpContainer(tnode);<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (tmpContainer.getType() == SINGLE) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string t = tmpContainer.getName();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moClassValueContainerVector[k].headerFields.push_back(t);<br />
&nbsp; &nbsp; &nbsp;  } else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ....<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ....<br />
&nbsp; &nbsp; &nbsp;  }<br />
}</code><hr />
</div>I cannot push_back(t). I examined the code with debugger, t has correct string value assigned, but even after 20-30 iterations, there is no element for headerFields vector. What is wrong here?<br />
<br />
Thanks in advance...<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>fnoyan</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156979-cannot-push_back-string-end-vector.html</guid>
		</item>
		<item>
			<title>terminology - pointer to array of ... or just array of?</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156973-terminology-pointer-array-just-array.html</link>
			<pubDate>Thu, 23 May 2013 23:24:29 GMT</pubDate>
			<description><![CDATA[Example: 
 
 
Code: 
--------- 
char *aps[5] = {{"aps zero "}, {"aps one  "}, {"aps two  "}, 
                {"aps three"}, {"aps four "}}; 
--------- 
For this example, using the debugger, aps is a pointer to the first of 5 pointers to the initial characters of 5 strings. If aps is placed in the...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Example:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">char *aps[5] = {{&quot;aps zero &quot;}, {&quot;aps one&nbsp; &quot;}, {&quot;aps two&nbsp; &quot;},<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&quot;aps three&quot;}, {&quot;aps four &quot;}};</code><hr />
</div>For this example, using the debugger, aps is a pointer to the first of 5 pointers to the initial characters of 5 strings. If aps is placed in the &quot;watch&quot; window it shows up as char **aps, but expanding it will show exactly 5 pointers. (If the above code was char** aps = malloc(...), then the watch window would only show aps and expanding it would only show *aps.)<br />
<br />
My issue is the terminology for what aps is. In C / C++, the name of an array implies a pointer to the first element of that array, so that (*aps) == &amp;aps[0];, so it seems that aps should be called an array of pointers (to the initial characters of strings).<br />
<br />
However some articles call aps a pointer to an array of pointers, but this would imply a second dereference is needed, since there would be one dereference for the pointer, and a second dereference for the array. (**aps) = &amp;(*aps)[0]). This terminology seems to conflict with how C / C++ handles arrays when referenced by the name, such as passing the name of an array as a function parameter.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>rcgldr</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156973-terminology-pointer-array-just-array.html</guid>
		</item>
		<item>
			<title>Quick question (beginner)</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156970-quick-question-beginner.html</link>
			<pubDate>Thu, 23 May 2013 19:30:17 GMT</pubDate>
			<description><![CDATA[The following code fragment: 
 
Code: 
--------- 
#include <iostream> 
#include <string> 
 
using namespace std; 
 
int main()]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->The following code fragment:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;iostream&gt;<br />
#include &lt;string&gt;<br />
<br />
using namespace std;<br />
<br />
int main() <br />
{<br />
char input[300], *p, *q[300], **r = q;<br />
<br />
&nbsp;cin.getline(input, 300);<br />
<br />
&nbsp;for (p = input; *p; p++)<br />
&nbsp;  switch (tolower(*p)) {<br />
&nbsp;  case 'e':<br />
&nbsp; &nbsp;  *r++ = p;<br />
&nbsp; &nbsp;  break;<br />
&nbsp;  case '.':<br />
&nbsp;  case '\'':<br />
&nbsp;  case ' ':<br />
&nbsp; &nbsp;  *p = '\0';<br />
&nbsp; &nbsp;  break; }<br />
&nbsp;*r = 0;<br />
<br />
&nbsp;for (r = q; *r; r++)<br />
&nbsp;  cout &lt;&lt; *r &lt;&lt; &quot; &quot;;<br />
<br />
&nbsp;cout &lt;&lt; endl;<br />
}</code><hr />
</div>was given as an example exam for my introduction programming course. What i don't understand is the use of the *p and *r as the middle argument in the for loops. I've only used inequalities for that location, so i have no idea what that means for pointers. Any help is appreciated.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>JMaxwell</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156970-quick-question-beginner.html</guid>
		</item>
		<item>
			<title>Trouble with custom allocator</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156969-trouble-custom-allocator.html</link>
			<pubDate>Thu, 23 May 2013 19:24:41 GMT</pubDate>
			<description><![CDATA[This question is partially related to Boost so I'm hoping someone here will still be able to help. I haven't been able to find a Boost forum anywhere, only a mailing list. 
 
I'll start by stating the problem I'm trying to solve. I want to be able to look up both negative and positive values and...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->This question is partially related to Boost so I'm hoping someone here will still be able to help. I haven't been able to find a Boost forum anywhere, only a mailing list.<br />
<br />
I'll start by stating the problem I'm trying to solve. I want to be able to look up both negative and positive values and have them map to some other value. So I'm thinking some kind of map is the best way to do this. From reading about map, it sounds like it's slow and has O(n) since it iterates from the start of the map up to the key. If I'm wrong about that, let me know.<br />
<br />
So instead, I plan to use an unordered map. Specifically Boost's unordered map since I don't have the standard unordered map available to me.<br />
<br />
Here's where it gets tricky. The values I want to use as keys are floats. I also want to use a preset pool of memory. After a lot of googling, I found a solution that works with all of this except it only works on std::maps. When I try to use a custom allocator with boost::unordered_map, I get a segfault on my 4th insert into my map, and the 3rd insert ends up storing a wrong value (again, when used with std::map, everything works fine).<br />
<br />
Is there anyone here familiar enough with Boost to see what is causing this? It could also be a general C++ error, I'm not sure. You'll probably also notice I've commented out code dealing with freeing any memory. That's because I don't care about freeing the maps memory. The map is populated once on start up and then only read from until the program exits. I didn't want to deal with that extra complication since I really didn't need to.<br />
<br />
Custom Allocator header<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#ifndef __CUSTOM_ALLOCATOR_H__<br />
#define __CUSTOM_ALLOCATOR_H__<br />
<br />
#include &lt;assert.h&gt;<br />
#include &lt;limits.h&gt;<br />
<br />
template&lt;class T&gt;<br />
class Custom_Allocator<br />
{<br />
<br />
public:<br />
<br />
&nbsp; typedef T value_type;<br />
&nbsp; typedef size_t size_type;<br />
&nbsp; typedef ptrdiff_t difference_type;<br />
&nbsp; typedef T* pointer;<br />
&nbsp; typedef const T* const_pointer;<br />
&nbsp; typedef T&amp; reference;<br />
&nbsp; typedef const T&amp; const_reference;<br />
<br />
&nbsp; Custom_Allocator( signed char *pool, int nPoolSize )<br />
&nbsp; {<br />
&nbsp; &nbsp; Init();<br />
&nbsp; &nbsp; m_pool = pool;<br />
&nbsp; &nbsp; m_nPoolSize = nPoolSize;<br />
&nbsp; }<br />
<br />
&nbsp; Custom_Allocator( int n )<br />
&nbsp; {<br />
&nbsp; &nbsp; Init();<br />
&nbsp; }<br />
<br />
&nbsp; Custom_Allocator()<br />
&nbsp; {<br />
&nbsp; &nbsp; Init();<br />
&nbsp; }<br />
<br />
&nbsp; void Init()<br />
&nbsp; {<br />
&nbsp; &nbsp; m_pool = 0;<br />
&nbsp; &nbsp; m_nPoolSize = 0;<br />
&nbsp; &nbsp; g_nCnt = 0;<br />
&nbsp; &nbsp; g_nTot = 0;<br />
&nbsp; }<br />
<br />
&nbsp; Custom_Allocator( const Custom_Allocator &amp;obj ) // copy constructor<br />
&nbsp; {<br />
&nbsp; &nbsp; Init();<br />
&nbsp; &nbsp; m_pool = obj.m_pool;<br />
&nbsp; &nbsp; m_nPoolSize = obj.m_nPoolSize;<br />
<br />
&nbsp; }<br />
<br />
private:<br />
<br />
&nbsp; long g_nCnt; // total # blocks allocated<br />
&nbsp; long g_nTot; // total allocated<br />
<br />
&nbsp; void operator =( const Custom_Allocator &amp; );<br />
<br />
public:<br />
<br />
&nbsp; signed char *m_pool;<br />
&nbsp; unsigned m_nPoolSize;<br />
<br />
&nbsp; template&lt;class _Other&gt;<br />
&nbsp; Custom_Allocator( const Custom_Allocator&lt; _Other &gt; &amp;other )<br />
&nbsp; {<br />
&nbsp; &nbsp; Init();<br />
&nbsp; &nbsp; m_pool = other.m_pool;<br />
&nbsp; &nbsp; m_nPoolSize = other.m_nPoolSize;<br />
&nbsp; }<br />
<br />
&nbsp; ~Custom_Allocator()<br />
&nbsp; {<br />
<br />
&nbsp; }<br />
<br />
&nbsp; template&lt;class U&gt;<br />
&nbsp; struct rebind<br />
&nbsp; {<br />
&nbsp; &nbsp; typedef Custom_Allocator&lt; U &gt; other;<br />
&nbsp; };<br />
<br />
&nbsp; pointer&nbsp; address( reference r ) const<br />
&nbsp; {<br />
&nbsp; &nbsp; return &amp;r;<br />
&nbsp; }<br />
<br />
&nbsp; const_pointer address( const_reference r ) const<br />
&nbsp; {<br />
&nbsp; &nbsp; return &amp;r;<br />
&nbsp; }<br />
<br />
&nbsp; pointer allocate( size_type n, const void* /*hint*/= 0 )<br />
&nbsp; {<br />
&nbsp; &nbsp; pointer p = 0;<br />
&nbsp; &nbsp; unsigned nSize = n * sizeof(T);<br />
<br />
&nbsp; &nbsp; if( m_pool ) // if we have a mem pool from which to allocated<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; p = (pointer) m_pool;// just return the next available mem in the pool<br />
<br />
&nbsp; &nbsp; &nbsp; if( g_nTot + nSize &gt; m_nPoolSize )<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; assert( 0 );//,&quot;out of mem pool&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
&nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; m_pool += nSize; // and bump the pointer<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; else<br />
&nbsp; &nbsp; {<br />
//&nbsp; &nbsp; &nbsp; p = (pointer) malloc( nSize );// no pool: just use malloc<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; g_nCnt += 1;<br />
&nbsp; &nbsp; g_nTot += nSize;<br />
&nbsp; &nbsp; assert( p );<br />
<br />
&nbsp; &nbsp; return p;<br />
&nbsp; }<br />
<br />
&nbsp; void deallocate( pointer p, size_type /*n*/)<br />
&nbsp; {<br />
//&nbsp; &nbsp; if( !m_pool )// if there's a pool, nothing to do<br />
//&nbsp; &nbsp; {<br />
//&nbsp; &nbsp; &nbsp; free( p );<br />
//&nbsp; &nbsp; }<br />
&nbsp; }<br />
<br />
&nbsp; void construct( pointer p, const T&amp; val )<br />
&nbsp; {<br />
&nbsp; &nbsp; new (p) T( val );<br />
&nbsp; }<br />
<br />
&nbsp; void destroy( pointer p )<br />
&nbsp; {<br />
&nbsp; &nbsp; p-&gt;~T();<br />
&nbsp; }<br />
<br />
&nbsp; size_type max_size() const<br />
&nbsp; {<br />
&nbsp; &nbsp; return ULONG_MAX / sizeof(T);<br />
&nbsp; }<br />
};<br />
<br />
template&lt;class T&gt;<br />
bool operator==( const Custom_Allocator&lt; T &gt;&amp; left, const Custom_Allocator&lt; T &gt;&amp; right )<br />
{<br />
&nbsp; if( left.m_pool == right.m_pool )<br />
&nbsp; {<br />
&nbsp; &nbsp; return true;<br />
&nbsp; }<br />
&nbsp; return false;<br />
}<br />
<br />
template&lt;class T&gt;<br />
bool operator!=( const Custom_Allocator&lt; T &gt;&amp; left, const Custom_Allocator&lt; T &gt;&amp; right )<br />
{<br />
&nbsp; if( left.m_pool != right.m_pool )<br />
&nbsp; {<br />
&nbsp; &nbsp; return true;<br />
&nbsp; }<br />
<br />
&nbsp; return false;<br />
}<br />
#endif</code><hr />
</div>Container header<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#ifndef __CONTAINER_H__<br />
#define __CONTAINER_H__<br />
#include &lt;boost/unordered_map.hpp&gt;<br />
#include &lt;Custom_Allocator.h&gt;<br />
<br />
using namespace std;<br />
using namespace __gnu_cxx;<br />
<br />
template&lt;float const &amp;threshold&gt; class compare_float {<br />
&nbsp; public:<br />
&nbsp; &nbsp; compare_float() : m_d(threshold){}<br />
&nbsp; &nbsp; inline bool operator()(const float &amp;x, const float &amp;y) const { return ((x + m_d) &lt; y); }// return abs(abs(x)-abs(y))&lt;m_d; }<br />
&nbsp; &nbsp; float m_d;<br />
};<br />
<br />
class Container<br />
{<br />
public:<br />
&nbsp; static const float map_threshold;<br />
<br />
&nbsp; Container();<br />
<br />
private:<br />
&nbsp; typedef Custom_Allocator&lt;std::pair&lt;float, float&gt; &gt; MyAllocator;<br />
&nbsp; boost::unordered_map&lt;float, float, boost::hash&lt;float&gt;, compare_float&lt;map_threshold&gt;, MyAllocator &gt;map_test;<br />
&nbsp; static const float c_max_key = 10.0f;<br />
&nbsp; static const float c_min_key = -10.0f;<br />
};<br />
#endif</code><hr />
</div>Container Source<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;Container.h&gt;<br />
#include &lt;stdio.h&gt;<br />
<br />
const float Container::map_threshold = .001f;<br />
signed char map_pool[sizeof(float)*3000];<br />
<br />
Container::Container() : map_test(MyAllocator(map_pool, sizeof(map_pool)))<br />
{<br />
&nbsp; for(float i = c_min_key; i &lt; c_max_key + .1f; i += .1f)<br />
&nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Storing: %f =&gt; %f.\n&quot;, i, (i*1000.0f));<br />
&nbsp; &nbsp; map_test[i] = i*1000.0f;<br />
&nbsp; &nbsp; printf(&quot;Stored:&nbsp; %f =&gt; %f.\n&quot;, i, map_test[i]);<br />
&nbsp; &nbsp; printf(&quot;++++++++++++++++++++++++++++++\n&quot;);<br />
&nbsp; }<br />
<br />
&nbsp; printf(&quot;=====================================\n&quot;);<br />
<br />
&nbsp; printf(&quot;%f.\n&quot;, map_test[1.2f]);<br />
&nbsp; printf(&quot;%f.\n&quot;, map_test[-1.2f]);<br />
&nbsp; printf(&quot;%f.\n&quot;, map_test[6.2f]);<br />
&nbsp; printf(&quot;%f.\n&quot;, map_test[-13.2f]);<br />
&nbsp; printf(&quot;%f.\n&quot;, map_test[.2f]);<br />
}</code><hr />
</div>Main<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;Container.h&gt;<br />
<br />
int main()<br />
{<br />
&nbsp; &nbsp; &nbsp; &nbsp; Container c;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
}</code><hr />
</div><!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>homer_3</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156969-trouble-custom-allocator.html</guid>
		</item>
		<item>
			<title>Basic combinatorics</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156960-basic-combinatorics.html</link>
			<pubDate>Thu, 23 May 2013 15:35:53 GMT</pubDate>
			<description><![CDATA[you have 3 integers given X,Y,Z 
X is amount of black soldiers 
Y is amount of purple soldiers 
Z is amount of white soldiers 
 
Calculate how many variations there are if black and white can't stand togethere (a purple must be inbetween). What would be the formula in the case if variations can't...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->you have 3 integers given X,Y,Z<br />
X is amount of black soldiers<br />
Y is amount of purple soldiers<br />
Z is amount of white soldiers<br />
<br />
Calculate how many variations there are if black and white can't stand togethere (a purple must be inbetween). What would be the formula in the case if variations can't and if they can repeat.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>Tobias Mihel</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156960-basic-combinatorics.html</guid>
		</item>
		<item>
			<title>urgent help needed with c++ webpage read data</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156955-urgent-help-needed-cplusplus-webpage-read-data.html</link>
			<pubDate>Thu, 23 May 2013 10:16:30 GMT</pubDate>
			<description>hi 
 
 
I am new to c++ web development for windows. I need to connect to webpage URL from c++ and fetch some data from website line by line. how this can be achieved? I am new to windows sockets also. Do I need winInet or winHTTP apis? any code is available for understanding basic work flow?</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->hi<br />
<br />
<br />
I am new to c++ web development for windows. I need to connect to webpage URL from c++ and fetch some data from website line by line. how this can be achieved? I am new to windows sockets also. Do I need winInet or winHTTP apis? any code is available for understanding basic work flow?<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>leo2008</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156955-urgent-help-needed-cplusplus-webpage-read-data.html</guid>
		</item>
		<item>
			<title>Solution problem</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156951-solution-problem.html</link>
			<pubDate>Thu, 23 May 2013 08:32:54 GMT</pubDate>
			<description>I have problem with solution for my homework. I have to write program which calculates number of girls that we can get their phone number and how much we need to pay. Input looks like this: 
 
5 - our starting budget; 
5 - number of friends; 
Mary 
Angie 
John 
Christian 
Peter - starting index is...</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->I have problem with solution for my homework. I have to write program which calculates number of girls that we can get their phone number and how much we need to pay. Input looks like this:<br />
<br />
5 - our starting budget;<br />
5 - number of friends;<br />
Mary<br />
Angie<br />
John<br />
Christian<br />
Peter - starting index is 1, and final is 5(because we are index 0)<br />
2 - number of girls we are interested in<br />
1 - index of girl(Mary)<br />
2 - index of girl(Angie)<br />
5 - number of connections between friends<br />
0 3 0 - friend[0](we) knows friend[3] and needs to pay 0 for his number<br />
3 4 5 - friend[3] knows friend[4] and he wants to be payed 5 bucks for friend[4] telephone number<br />
3 5 7 - friend[3] knows friend[5] and he wants to be payed 7 bucks for friend[5] telephone number<br />
4 1 9 - friend[4] knows friend[1] and he wants to be payed 9 bucks<br />
for his number<br />
5 1 1 - friend[5] knows friend[1] and he wants to be payed 1 dollar for his number<br />
<br />
Output should be:<br />
Mary 2 - we can get only Mary's number(and we need to pay 8 bucks for it, because we want to take cheaper option)<br />
<br />
Real input for girl name should be F01234 and that kind of things, so we can find out who are girls.<br />
<br />
Is it better to solve this via class or just in main?<br />
<br />
I have this so far:<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#define MAXF 20000&nbsp; &nbsp; //max num of friends<br />
#define MAXC 1000000&nbsp; &nbsp; //max num of connections between them<br />
#define MAXL 20&nbsp; &nbsp; //max num of girls we are interested<br />
#define MAXB 100000000&nbsp; &nbsp; //max budget<br />
<br />
<br />
int main()<br />
{<br />
&nbsp; &nbsp; int budget;<br />
&nbsp; &nbsp; cin &gt;&gt; budget;&nbsp; &nbsp; cin.get();<br />
<br />
<br />
&nbsp; &nbsp; int friendsCnt;<br />
&nbsp; &nbsp; cin &gt;&gt; friendsCnt;&nbsp; &nbsp; cin.get();<br />
&nbsp; &nbsp; string friends[MAXF];<br />
&nbsp; &nbsp; friends[0] = &quot;Tvrtko&quot;;<br />
&nbsp; &nbsp; for(int i = 1; i &lt; friendsCnt+1; i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; getline(cin, friends[i]);<br />
&nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; int loversCnt;<br />
&nbsp; &nbsp; cin &gt;&gt; loversCnt;&nbsp; &nbsp; cin.get();<br />
&nbsp; &nbsp; string lovers[MAXL];<br />
&nbsp; &nbsp; for(int i = 0; i &lt; loversCnt; i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; int tmp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; cin &gt;&gt; tmp;&nbsp; &nbsp; cin.get();<br />
&nbsp; &nbsp; &nbsp; &nbsp; lovers[i] = friends[tmp];<br />
&nbsp; &nbsp; }<br />
<br />
<br />
&nbsp; &nbsp; int connectionsCnt;<br />
&nbsp; &nbsp; cin &gt;&gt; connectionsCnt;&nbsp; &nbsp; cin.get();<br />
&nbsp; &nbsp; for(int i = 0; i &lt; connectionsCnt; i++)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; int indexF, indexC, price;<br />
&nbsp; &nbsp; &nbsp; &nbsp; cin &gt;&gt; indexF &gt;&gt; indexC &gt;&gt; price;&nbsp; &nbsp; cin.get();<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return 0;<br />
}</code><hr />
</div>I don't know how to proceed with this code. Any kind of help is appreciated.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>yahzee</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156951-solution-problem.html</guid>
		</item>
		<item>
			<title>C++ beginner - Sum of multiples less than 100</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156950-cplusplus-beginner-sum-multiples-less-than-100-a.html</link>
			<pubDate>Thu, 23 May 2013 07:41:34 GMT</pubDate>
			<description><![CDATA[Hey guys, this is my first post here.  I am a beginner in C++ and have a question for a homework assignment.  I have read my book over and over and can't seem to figure out how to code this properly. 
 
What I want it to do is have the user input a number: ex. 5 and then have the code give the sum...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hey guys, this is my first post here.  I am a beginner in C++ and have a question for a homework assignment.  I have read my book over and over and can't seem to figure out how to code this properly.<br />
<br />
What I want it to do is have the user input a number: ex. 5 and then have the code give the sum for all the multiples of 5 less than 100, so it should be equal to 950 in this example.<br />
<br />
Anyway, I have got so far to get it to list the numbers, but I need the sum of those numbers without all the text displayed every time.<br />
<br />
I have chosen to use the FOR, but I am wondering if I should implement WHILE loop in my coding somewhere.  I just don't know how to go about it for this problem.<br />
<br />
Again, this is my first post (and definitely not my last!) I hope I have read the rules properly.  It is my first programming class in school, and I am seeing a tutor tomorrow and the next day, I would just like to have a better grasp of this before going in tomorrow.  <br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">#include &lt;iostream&gt;<br />
using namespace std;<br />
<br />
int addMultiples()<br />
{<br />
&nbsp;  // Start<br />
&nbsp;  cout &lt;&lt; &quot;What multiples are we adding? &quot;;<br />
&nbsp;  int start;<br />
&nbsp;  cin &gt;&gt; start;<br />
<br />
&nbsp;  int increment = start;<br />
<br />
&nbsp;  for (int count = start; count &lt;= 100; count += increment)<br />
&nbsp;  cout &lt;&lt; &quot;The sum of multiples of &quot; &lt;&lt; start<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt; &quot; less than 100 are: &quot; &lt;&lt; count &lt;&lt; endl;<br />
<br />
&nbsp;  return 0;<br />
}<br />
<br />
<br />
<br />
<br />
int main()<br />
{<br />
&nbsp;  addMultiples();<br />
&nbsp;  return 0;<br />
}</code><hr />
</div>I want the output like this:<br />
<br />
What multiples are we adding? 5<br />
The sum of the multiples of 5 less than 100 are: 950<br />
<br />
Thanks for your help and explanations!<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>Bronzy</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156950-cplusplus-beginner-sum-multiples-less-than-100-a.html</guid>
		</item>
		<item>
			<title>Console C++</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156949-console-cplusplus.html</link>
			<pubDate>Thu, 23 May 2013 07:16:05 GMT</pubDate>
			<description><![CDATA[Hi, a month ago I completed a C++ class. Everything they taught was on the console screen, that is, the text only interface. 
And then, I find out that C++ programs these days are all GUI and we don't use iostream and all that. 
 
Does this mean that everything I learnt was wasted?]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi, a month ago I completed a C++ class. Everything they taught was on the console screen, that is, the text only interface.<br />
And then, I find out that C++ programs these days are all GUI and we don't use iostream and all that.<br />
<br />
Does this mean that everything I learnt was wasted?<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>Dakshin</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156949-console-cplusplus.html</guid>
		</item>
		<item>
			<title>Lexing file into binary search tree</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156944-lexing-file-into-binary-search-tree.html</link>
			<pubDate>Wed, 22 May 2013 22:21:51 GMT</pubDate>
			<description><![CDATA[Standard example. I have a large text file and I wish to lex it into words. I tell the program that all words are delimited by ' ' ';' ':' and '\n'. 
 
When I run the program it seems to be outputting the occurances of the letters and not the words. Im gobsmacked, I dont know what the hell is going...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Standard example. I have a large text file and I wish to lex it into words. I tell the program that all words are delimited by ' ' ';' ':' and '\n'.<br />
<br />
When I run the program it seems to be outputting the occurances of the letters and not the words. Im gobsmacked, I dont know what the hell is going on. Heres the function that lexes letters and not words. I want words dammit words!!<br />
<br />
First youll see I define root node and point it to null; This forms the base of the BST.<br />
Then keep munching one character at a time until EOF reached. If the character is not a delimiter, assign it to &quot;word&quot; string, character by character. If it is a delimiter, take the so-far-constructed &quot;word&quot; and chuck it in the BST, then clear the word string through .clear().<br />
Repeat until done. But its not working.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">struct masternode* lexical_scanner(ifstream* inputfile) {<br />
&nbsp; &nbsp; string word;<br />
&nbsp; &nbsp; char c;<br />
&nbsp; &nbsp; struct masternode* root = NULL;<br />
&nbsp; &nbsp; while (c!=EOF){<br />
&nbsp; &nbsp; &nbsp; &nbsp; if((c = (*inputfile).get()) != ' ' &amp;&amp; c != ':' &amp;&amp; c!= ';' &amp;&amp; c!='\n')<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; word += c;<br />
&nbsp; &nbsp; &nbsp; &nbsp; root = insert(root, word);<br />
&nbsp; &nbsp; &nbsp; &nbsp; word.clear();<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return root;<br />
}</code><hr />
</div>EDIT: All the other functions in the source file are just fine, I've tested them in other apps and they are purpose built.<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>Vespasian</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156944-lexing-file-into-binary-search-tree.html</guid>
		</item>
		<item>
			<title>passing a vector to a function, getting negative length and size, aka segault</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156941-passing-vector-function-getting-negative-length-size-aka-segault.html</link>
			<pubDate>Wed, 22 May 2013 21:26:43 GMT</pubDate>
			<description><![CDATA[Hello, 
 
I am writing a raytracer, and currently I'm working on creating a bounding volume hierarchy to accelerate the process. To do this, I am first creating a vector that holds each of the objects in the scene, and passing this vector to the constructor for my BVH. 
 
Code: 
--------- 
//in...]]></description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hello,<br />
<br />
I am writing a raytracer, and currently I'm working on creating a bounding volume hierarchy to accelerate the process. To do this, I am first creating a vector that holds each of the objects in the scene, and passing this vector to the constructor for my BVH.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">//in header<br />
BVH_Node* bvh;<br />
//in main raytrace function<br />
bvh = new BVH_Node(objList,0);</code><hr />
</div>The BVH_Node constructor:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">//here's how the beginning of it looks<br />
BVH_Node::BVH_Node(vector&lt;GeomObj*&gt; list, int axis){<br />
&nbsp; int size = list.size(); //number of elements in list<br />
&nbsp; this-&gt;isObj = false;<br />
&nbsp; if(size == 1){<br />
&nbsp; &nbsp; this-&gt;left = makeLeaf(list[0]);<br />
&nbsp; &nbsp; this-&gt;right = makeLeaf(NULL);<br />
&nbsp; &nbsp; this-&gt;bb = list[0]-&gt;bb;<br />
&nbsp; &nbsp; return;<br />
&nbsp; }<br />
&nbsp; if(size == 2){<br />
&nbsp; &nbsp; this-&gt;left = makeLeaf(list[0]);<br />
&nbsp; &nbsp; this-&gt;right = makeLeaf(list[1]);<br />
&nbsp; &nbsp; this-&gt;bb = combineBoxes(list[0]-&gt;bb,list[1]-&gt;bb);<br />
&nbsp; &nbsp; return;<br />
&nbsp; }<br />
//the rest of it<br />
}</code><hr />
</div>I am testing a scene that has only 2 objects, and so it goes to the size == 2 check. The first time it hits makeLeaf(), I segfault. I've used both gdb and valgrind, and of course it's a memory mapping error. gdb's backtrace tells me that the length of the vector I've passed in is -805305610 and the capacity is -21, and that it is inside my makeLeaf() function that the error occurs. Here's the function:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">BVH_Node* BVH_Node::makeLeaf(GeomObj* v){<br />
&nbsp; BVH_Node* node;<br />
&nbsp; node-&gt;obj = v;<br />
&nbsp; node-&gt;isObj = true;<br />
&nbsp; return node;<br />
}</code><hr />
</div>The segfault happens at <div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">node-&gt;obj = v;</code><hr />
</div>Could someone help me understand why this is happening? If I run my raytracer without a BVH, the objList works perfectly.<br />
<br />
Thanks<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>synhyborex</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156941-passing-vector-function-getting-negative-length-size-aka-segault.html</guid>
		</item>
		<item>
			<title>Timer OOP Method (I/O)</title>
			<link>http://cboard.cprogramming.com/cplusplus-programming/156938-timer-oop-method-i-o.html</link>
			<pubDate>Wed, 22 May 2013 19:10:15 GMT</pubDate>
			<description>Hi, here is an OOP based time program which is although static and works on input or initializing variables here for u: 
 
 
 
Code: 
--------- 
time1.h 
 
#pragma once 
class time1</description>
			<content:encoded><![CDATA[<div><!-- google_ad_section_start -->Hi, here is an OOP based time program which is although static and works on input or initializing variables here for u:<br />
<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">time1.h<br />
<br />
#pragma once<br />
class time1<br />
{<br />
public:<br />
time1(int=0, int=0, int=0);<br />
void setTime(int, int, int);<br />
void printMilitary();<br />
void printStandard();<br />
~time1(void);<br />
private:<br />
&nbsp; &nbsp; int hour, minute, second;<br />
&nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; <br />
};</code><hr />
</div><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">time1.cpp<br />
<br />
#include &quot;time1.h&quot;<br />
#include &lt;iostream&gt;<br />
using namespace std;<br />
<br />
time1::time1(int hr, int min, int sec)<br />
{<br />
&nbsp; &nbsp; setTime(hr, min, sec);<br />
}<br />
<br />
void time1::setTime(int h, int m, int s)<br />
{<br />
&nbsp; &nbsp; hour=&nbsp; (h&gt;=0 &amp;&amp; h&lt;24) ? h:0;<br />
&nbsp; &nbsp; minute=(m&gt;=0 &amp;&amp; m&lt;60) ? m:0;<br />
&nbsp; &nbsp; second=(s&gt;=0 &amp;&amp; s&lt;60) ? s:0;<br />
}<br />
<br />
void time1::printMilitary()<br />
{<br />
&nbsp; &nbsp; cout&lt;&lt; (hour&lt;10 ? &quot;0&quot; : &quot;&quot;) &lt;&lt; hour &lt;&lt; &quot;:&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt; (minute &lt;10 ? &quot;0&quot; : &quot;&quot;)&lt;&lt;minute;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
}<br />
<br />
void time1::printStandard()<br />
{<br />
&nbsp; &nbsp; cout&lt;&lt; ((hour==0 || hour==12) ? 12 : hour % 12)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt; &quot;:&quot; &lt;&lt; (minute &lt; 10 ? &quot;0&quot; : &quot;&quot;) &lt;&lt; minute<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt; &quot;:&quot; &lt;&lt; (second &lt; 10 ? &quot;0&quot; : &quot;&quot;) &lt;&lt;second<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt;(hour &lt; 12 ? &quot; AM&quot; : &quot; PM&quot;);<br />
}<br />
time1::~time1(void)<br />
{<br />
}</code><hr />
</div><div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">source file source.cpp<br />
<br />
#include&lt;iostream&gt;<br />
#include&quot;time1.h&quot;<br />
using namespace std;<br />
void main()<br />
{<br />
&nbsp; &nbsp; time1 t1, t2(2), t3(21, 34), t4(12,25, 42), t5(27,74,99);<br />
<br />
&nbsp; &nbsp; cout&lt;&lt; &quot;Default Time: \n&quot;;<br />
&nbsp; &nbsp; t1.printMilitary();<br />
&nbsp; &nbsp; cout&lt;&lt;endl;<br />
&nbsp; &nbsp; t1.printStandard();<br />
<br />
&nbsp; &nbsp; cout&lt;&lt; &quot;\n\nHour input, minutes and seconds are default: \n&quot;;<br />
&nbsp; &nbsp; t2.printMilitary();<br />
&nbsp; &nbsp; cout&lt;&lt;endl;<br />
&nbsp; &nbsp; t2.printStandard();<br />
<br />
&nbsp; &nbsp; cout&lt;&lt;&quot;\n\nhours and minutes specified, seconds default: \n&quot;;<br />
&nbsp; &nbsp; t3.printMilitary();<br />
&nbsp; &nbsp; cout&lt;&lt;&quot;\n&quot;;<br />
&nbsp; &nbsp; t3.printStandard();<br />
<br />
&nbsp; &nbsp; cout&lt;&lt;&quot;\n\nEverything is specified: \n&quot;;<br />
&nbsp; &nbsp; t4.printMilitary();<br />
&nbsp; &nbsp; cout&lt;&lt;endl;<br />
&nbsp; &nbsp; t4.printStandard();<br />
<br />
&nbsp; &nbsp; cout&lt;&lt;&quot;\n\nall invalid values given: \n&quot;;<br />
&nbsp; &nbsp; t5.printMilitary();<br />
&nbsp; &nbsp; cout&lt;&lt;endl;<br />
&nbsp; &nbsp; t5.printStandard();<br />
&nbsp; &nbsp; cout&lt;&lt;endl;<br />
&nbsp; &nbsp; system(&quot;pause&quot;);<br />
<br />
&nbsp; &nbsp; <br />
<br />
}</code><hr />
</div><br />
Any Question, feel free to ask!<!-- google_ad_section_end --></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/cplusplus-programming/">C++ Programming</category>
			<dc:creator>shansajid</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/cplusplus-programming/156938-timer-oop-method-i-o.html</guid>
		</item>
	</channel>
</rss>
