<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 7.13 &#8212; Command line arguments</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 12:30:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: AUASP</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-95691</link>
		<dc:creator>AUASP</dc:creator>
		<pubDate>Mon, 11 Jul 2011 14:09:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-95691</guid>
		<description>Double quotes(&quot;) are not taken as command line arguments.
Only way to inclde double quotes is preceeding quotes with &#039;\&#039;.Eg. \&quot;</description>
		<content:encoded><![CDATA[<p>Double quotes(&#8220;) are not taken as command line arguments.<br />
Only way to inclde double quotes is preceeding quotes with &#8216;\&#8217;.Eg. \&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-91239</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 01 Sep 2010 21:29:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-91239</guid>
		<description>Do you want to include:

#include 

in the code that people copy to their clipboard so that errors don&#039;t occur?
E.g.
 g++ j35.cpp -g -o xxx
j35.cpp: In function ‘int main(int, char**)’:
j35.cpp:8: error: ‘cout’ was not declared in this scope
j35.cpp:8: error: ‘endl’ was not declared in this scope
j35.cpp:9: error: ‘exit’ was not declared in this scope



That is:
&lt;pre&gt;
#include &lt;iostream&gt;
int main(int argc, char *argv[])
{
    using namespace std;
    // If the user didn&#039;t provide a filename command line argument,
    // print an error and exit.
    if (argc &lt;= 1)
    {
        cout &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;Filename&gt;&quot; &lt;&lt; endl;
        exit(1);
    }

    char *pFilename = argv[1];

    // open file and process it
}

&lt;!--formatted--&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Do you want to include:</p>
<p>#include </p>
<p>in the code that people copy to their clipboard so that errors don&#8217;t occur?<br />
E.g.<br />
 g++ j35.cpp -g -o xxx<br />
j35.cpp: In function ‘int main(int, char**)’:<br />
j35.cpp:8: error: ‘cout’ was not declared in this scope<br />
j35.cpp:8: error: ‘endl’ was not declared in this scope<br />
j35.cpp:9: error: ‘exit’ was not declared in this scope</p>
<p>That is:</p>
<pre>
#include &lt;iostream&gt;
int main(int argc, char *argv[])
{
    using namespace std;
    // If the user didn&#39;t provide a filename command line argument,
    // print an error and exit.
    if (argc &lt;= 1)
    {
        cout &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;Filename&gt;&quot; &lt;&lt; endl;
        exit(1);
    }

    char *pFilename = argv[1];

    // open file and process it
}

<!--formatted--></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: C++ Tutorial and Online Ebook</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-87431</link>
		<dc:creator>C++ Tutorial and Online Ebook</dc:creator>
		<pubDate>Wed, 30 Jun 2010 01:11:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-87431</guid>
		<description>[...] 7.13 Command line arguments [...]</description>
		<content:encoded><![CDATA[<p>[...] 7.13 Command line arguments [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dzmat</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-76919</link>
		<dc:creator>dzmat</dc:creator>
		<pubDate>Fri, 22 Jan 2010 09:27:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-76919</guid>
		<description>Even when there is no command line arguments passed to program, argc=1, because argv[0] is a name of executable and is always present.</description>
		<content:encoded><![CDATA[<p>Even when there is no command line arguments passed to program, argc=1, because argv[0] is a name of executable and is always present.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: baldo</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-66471</link>
		<dc:creator>baldo</dc:creator>
		<pubDate>Mon, 17 Aug 2009 14:57:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-66471</guid>
		<description>In Visual Studio, _tmain is a macro that expands to wmain according and _TCHAR expands to wchar_t.  
The problem is that you are using &#039;cout&#039; (which works with single wide strings) with a double wide string. 
&lt;pre&gt;
// This should work 
wcout &lt;&lt; argv[0] &lt;&lt; endl; 
&lt;!--formatted--&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>In Visual Studio, _tmain is a macro that expands to wmain according and _TCHAR expands to wchar_t.<br />
The problem is that you are using &#8216;cout&#8217; (which works with single wide strings) with a double wide string. </p>
<pre>
// This should work
wcout &lt;&lt; argv[0] &lt;&lt; endl;
<!--formatted--></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Quinn</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-63813</link>
		<dc:creator>Quinn</dc:creator>
		<pubDate>Mon, 06 Jul 2009 13:27:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-63813</guid>
		<description>Actually, argc always evaluates to at least one, even without any other command-line arguments. If it were just (argc &lt; 1) then you&#039;d end up with that if statement never evaluating to true, and the program most likely crashing due to trying to load up something that wasn&#039;t there if the user tried not giving any arguments.</description>
		<content:encoded><![CDATA[<p>Actually, argc always evaluates to at least one, even without any other command-line arguments. If it were just (argc &lt; 1) then you&#8217;d end up with that if statement never evaluating to true, and the program most likely crashing due to trying to load up something that wasn&#8217;t there if the user tried not giving any arguments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Quinn</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-63810</link>
		<dc:creator>Quinn</dc:creator>
		<pubDate>Mon, 06 Jul 2009 13:21:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-63810</guid>
		<description>You can set arguments automatically in Code::Blocks using the &lt;b&gt;Project -&gt; Set programs&#039; arguments&lt;/b&gt; menu option. Then when you build/run or just run it the program will always run with your selected arguments.</description>
		<content:encoded><![CDATA[<p>You can set arguments automatically in Code::Blocks using the <b>Project -&gt; Set programs&#8217; arguments</b> menu option. Then when you build/run or just run it the program will always run with your selected arguments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kurt</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-62453</link>
		<dc:creator>Kurt</dc:creator>
		<pubDate>Mon, 15 Jun 2009 08:07:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-62453</guid>
		<description>In the last example isn&#039;t there a off by 1 error?
&lt;pre&gt;
    if (argc &lt;= 1)
    {
        cout &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;Filename&gt;&quot; &lt;&lt; endl;
        exit(1);
    }
&lt;/pre&gt;

When there is a command line argument, argc = 1  then (argc &lt;= 1) is the same as  1 &lt;=1 what translates to true so the program exits.
It should be like this no?
&lt;pre&gt;
    if (argc &lt; 1)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>In the last example isn&#8217;t there a off by 1 error?</p>
<pre>
    if (argc &lt;= 1)
    {
        cout &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;Filename&gt;&quot; &lt;&lt; endl;
        exit(1);
    }
</pre>
<p>When there is a command line argument, argc = 1  then (argc &lt;= 1) is the same as  1 &lt;=1 what translates to true so the program exits.<br />
It should be like this no?</p>
<pre>
    if (argc &lt; 1)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohamad</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-62257</link>
		<dc:creator>Mohamad</dc:creator>
		<pubDate>Thu, 11 Jun 2009 08:36:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-62257</guid>
		<description>Nevermind I figured it out... all I had to do was go to the command line in Vista Start mean (which looks like a search instead of the run box you get in Windows XP) and type in the path to the file and the argument.  Thanks for all the good lessons.</description>
		<content:encoded><![CDATA[<p>Nevermind I figured it out&#8230; all I had to do was go to the command line in Vista Start mean (which looks like a search instead of the run box you get in Windows XP) and type in the path to the file and the argument.  Thanks for all the good lessons.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohamad</title>
		<link>http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/comment-page-1/#comment-62256</link>
		<dc:creator>Mohamad</dc:creator>
		<pubDate>Thu, 11 Jun 2009 08:21:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/#comment-62256</guid>
		<description>I am  confused as to how to pass command line arguments to main using CODE::BLOCKS any instructions?</description>
		<content:encoded><![CDATA[<p>I am  confused as to how to pass command line arguments to main using CODE::BLOCKS any instructions?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

