<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[C++ Konsolenanwendung Argumente überprüfen]]></title><description><![CDATA[<p>Hallo zusammen.. Ich mus im Geschäft eine Applikation schreiben, die Messwerte eines Messgerätes über den COM-Port ausliest und in ein CSV File schreibt.</p>
<p>Dies funktioniert wunderbar, jedoch muss ich nun noch einige zusätzliche Dinge programmieren und zwar sollen verschiedene Parameter angegeben werden wie:</p>
<p>-debug --&gt; Die messwerte Sollen auch in der Konsole ausgegeben werden.<br />
-v --&gt; Ähnlich wie -debug<br />
-variable --&gt; Messmodus soll gewählt werden können<br />
-range --&gt; Messbereich soll ausgewählt werden können(1-4)<br />
-version --&gt; Die Version der Applikation wird ausgegeben<br />
-help --&gt; Ein Hilfetext wird angezeigt</p>
<p>**Nun meine Frage:<br />
Wie kann ich überprüfenwie wie viele und welche(s) Argument(e) asgewählt wurden?</p>
<p>Kann man dies mit einer Switch Anweisung oder einer If-Verzweigung herausfinden?**</p>
<p>Bis jetzt habe ich erst diese überprüfung unten. Jedoch werden dort nur die Parameter überprüft, die benötigt werden um eine Voltmessung mit Standard Messbereich durchzuführen.<br />
Argumente: COM-Port, Baud-Rate und Range.<br />
Wird es ohne Parameter gestartet erscheint der Hilfe Text.</p>
<pre><code>[cpp]/////////////////////////////////////////////////////////////////////////////////////////
//							PARAMETER SETZEN										   //
/////////////////////////////////////////////////////////////////////////////////////////

	// how many parameters are given (argv[0] is the program path so the user didn't type any parameter
	switch(argc)
	{
		//The user will be informed, how to use the sniffer
	case 1:
		cout &lt;&lt; &quot;How to use Fluke 45 Reader: &quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;&gt;Fluke_45_reader.exe &lt;COM port&gt; [&lt;Baud rate&gt;]&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;COM port: The COM port, where the Fluke is connected.&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Baud rate: 9600, 19200 or 57600, default: 9600&quot; &lt;&lt; endl &lt;&lt; endl;
		cout &lt;&lt; &quot;Other Parameters:&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-debug		shows the messages from or to the Fluke with a time stamp&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-v		shows the same text, wich is also written in the log-file&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-range 1-4	Range:	1: 300mV   2: 3V   3: 30V   4: 300V&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-version	shows the version of the Fluke reader&quot; &lt;&lt; endl &lt;&lt; endl;
		cout &lt;&lt; &quot;To stop the sniffer press CTRL + C&quot; &lt;&lt; endl &lt;&lt; endl;
		break;

		//try to set the com port 
	case 2:
		iComPort = atoi(argv[1]);
		bArgsSet = true;

		break;

		//try to set Com port and baud rate
	case 3:
		iComPort  = atoi(argv[1]);
		iBaudRate = atoi(argv[2]);
		bArgsSet  = true;
		break;

	case 4:
		iComPort  = atoi(argv[1]);
		iBaudRate = atoi(argv[2]);
		Range     = atoi(argv[3]);
		bArgsSet  = true;
		break;
	}
[/cpp]
</code></pre>
<p>Bin froh über jede Hilfe kommme echt nicht weiter..<br />
Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275247/c-konsolenanwendung-argumente-überprüfen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 02:43:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275247.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 12 Oct 2010 06:43:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C++ Konsolenanwendung Argumente überprüfen on Tue, 12 Oct 2010 06:43:09 GMT]]></title><description><![CDATA[<p>Hallo zusammen.. Ich mus im Geschäft eine Applikation schreiben, die Messwerte eines Messgerätes über den COM-Port ausliest und in ein CSV File schreibt.</p>
<p>Dies funktioniert wunderbar, jedoch muss ich nun noch einige zusätzliche Dinge programmieren und zwar sollen verschiedene Parameter angegeben werden wie:</p>
<p>-debug --&gt; Die messwerte Sollen auch in der Konsole ausgegeben werden.<br />
-v --&gt; Ähnlich wie -debug<br />
-variable --&gt; Messmodus soll gewählt werden können<br />
-range --&gt; Messbereich soll ausgewählt werden können(1-4)<br />
-version --&gt; Die Version der Applikation wird ausgegeben<br />
-help --&gt; Ein Hilfetext wird angezeigt</p>
<p>**Nun meine Frage:<br />
Wie kann ich überprüfenwie wie viele und welche(s) Argument(e) asgewählt wurden?</p>
<p>Kann man dies mit einer Switch Anweisung oder einer If-Verzweigung herausfinden?**</p>
<p>Bis jetzt habe ich erst diese überprüfung unten. Jedoch werden dort nur die Parameter überprüft, die benötigt werden um eine Voltmessung mit Standard Messbereich durchzuführen.<br />
Argumente: COM-Port, Baud-Rate und Range.<br />
Wird es ohne Parameter gestartet erscheint der Hilfe Text.</p>
<pre><code>[cpp]/////////////////////////////////////////////////////////////////////////////////////////
//							PARAMETER SETZEN										   //
/////////////////////////////////////////////////////////////////////////////////////////

	// how many parameters are given (argv[0] is the program path so the user didn't type any parameter
	switch(argc)
	{
		//The user will be informed, how to use the sniffer
	case 1:
		cout &lt;&lt; &quot;How to use Fluke 45 Reader: &quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;&gt;Fluke_45_reader.exe &lt;COM port&gt; [&lt;Baud rate&gt;]&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;COM port: The COM port, where the Fluke is connected.&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Baud rate: 9600, 19200 or 57600, default: 9600&quot; &lt;&lt; endl &lt;&lt; endl;
		cout &lt;&lt; &quot;Other Parameters:&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-debug		shows the messages from or to the Fluke with a time stamp&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-v		shows the same text, wich is also written in the log-file&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-range 1-4	Range:	1: 300mV   2: 3V   3: 30V   4: 300V&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-version	shows the version of the Fluke reader&quot; &lt;&lt; endl &lt;&lt; endl;
		cout &lt;&lt; &quot;To stop the sniffer press CTRL + C&quot; &lt;&lt; endl &lt;&lt; endl;
		break;

		//try to set the com port 
	case 2:
		iComPort = atoi(argv[1]);
		bArgsSet = true;

		break;

		//try to set Com port and baud rate
	case 3:
		iComPort  = atoi(argv[1]);
		iBaudRate = atoi(argv[2]);
		bArgsSet  = true;
		break;

	case 4:
		iComPort  = atoi(argv[1]);
		iBaudRate = atoi(argv[2]);
		Range     = atoi(argv[3]);
		bArgsSet  = true;
		break;
	}
[/cpp]
</code></pre>
<p>Bin froh über jede Hilfe kommme echt nicht weiter..<br />
Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1964150</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964150</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Tue, 12 Oct 2010 06:43:09 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Konsolenanwendung Argumente überprüfen on Tue, 12 Oct 2010 07:13:31 GMT]]></title><description><![CDATA[<p>switch ist da ziemlich fehl am Platz. Ich würd ne for-(oder while) Schleife draus machen, den Fall ohne Argumente evtl. vorher mit nem if abfragen und dann ein argument nach dem anderen verwerten.<br />
Alternativ gibts auch Bibliotheken die sich um solche Kommandozeilenargumente kümmern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1964159</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964159</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Tue, 12 Oct 2010 07:13:31 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Konsolenanwendung Argumente überprüfen on Tue, 12 Oct 2010 07:31:37 GMT]]></title><description><![CDATA[<p>pumuckl schrieb:</p>
<blockquote>
<p>switch ist da ziemlich fehl am Platz. Ich würd ne for-(oder while) Schleife draus machen, den Fall ohne Argumente evtl. vorher mit nem if abfragen und dann ein argument nach dem anderen verwerten.</p>
</blockquote>
<p><strong>meinst du in etwa so?:</strong></p>
<pre><code>[cpp]
	if (argc = 0)
	{
				cout &lt;&lt; &quot;How to use Fluke 45 Reader: &quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;&gt;Fluke_45_reader.exe &lt;COM port&gt; [&lt;Baud rate&gt;]&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;COM port: The COM port, where the Fluke is connected.&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;Baud rate: 9600, 19200 or 57600, default: 9600&quot; &lt;&lt; endl &lt;&lt; endl;
		cout &lt;&lt; &quot;Other Parameters:&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-debug		shows the messages from or to the Fluke with a time stamp&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-v		shows the same text, wich is also written in the log-file&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-range 1-4	Range:	1: 300mV   2: 3V   3: 30V   4: 300V&quot; &lt;&lt; endl;
		cout &lt;&lt; &quot;-version	shows the version of the Fluke reader&quot; &lt;&lt; endl &lt;&lt; endl;
		cout &lt;&lt; &quot;To stop the sniffer press CTRL + C&quot; &lt;&lt; endl &lt;&lt; endl;
	}

	else
	{
		for( int i = 1; i&lt;= argc; i++)
		{
			if (strcmp (argv[i], &quot;-debug&quot;) == 1)
			{
				DebugMode == true;
			}

			if (strcmp (argv[i], 9600) == 1)
			{
				iBaudRate = 9600;
			}

			if (strcmp (argv[i], 19200) == 1)
			{
				iBaudRate = 19200;
			}

			if (strcmp (argv[i], 57600) == 1)
			{
				iBaudRate = 57600;
			}

			if (strcmp (argv[i], 1) == 1)
			{
				iBaudRate = 1;
			}

			if (strcmp (argv[i], 2) == 1)
			{
				iBaudRate = 2;
			}

			if (strcmp (argv[i], 3) == 1)
			{
				iBaudRate = 3;
			}

			if (strcmp (argv[i], 4) == 1)
			{
				iBaudRate = 4;
			}

			if (strcmp (argv[i], 5) == 1)
			{
				iBaudRate = 5;
			}

			if (strcmp (argv[i], 6) == 1)
			{
				iBaudRate = 6;
			}

			if (strcmp (argv[i], &quot;-help&quot;) == 1)
			{
				showHelpText();
			}

			if (strcmp (argv[i], 2) == 1)
			{
				DebugMode == true;
			}
		}

	}[/cpp]
</code></pre>
<p>Meiner Meinung nach gibt dies viel zu viel Code und wirkt unüberichtlich.. Ausserdem können nie alle möglichen Eingaben verwertet werden.</p>
<p><strong>Hast du vielleicht ein Beispiel wie man 2-3 Argumente überprüfen könnte?</strong></p>
<p>pumuckl schrieb:</p>
<blockquote>
<p>Alternativ gibts auch Bibliotheken die sich um solche Kommandozeilenargumente kümmern.</p>
</blockquote>
<p><strong>Wo finde ich diese Bibliotheken? Sind das Windows standard Bibliotheken oder muss ich die zusätzlich downloaden?</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1964169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964169</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Tue, 12 Oct 2010 07:31:37 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Konsolenanwendung Argumente überprüfen on Tue, 12 Oct 2010 07:49:25 GMT]]></title><description><![CDATA[<p>Eine Standardfunktion dafür gibt es nicht, GNU hat dafür aber getopt:</p>
<p><a href="http://www.gnu.org/software/libc/manual/html_node/Getopt.html" rel="nofollow">http://www.gnu.org/software/libc/manual/html_node/Getopt.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1964177</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964177</guid><dc:creator><![CDATA[Wutz]]></dc:creator><pubDate>Tue, 12 Oct 2010 07:49:25 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Konsolenanwendung Argumente überprüfen on Tue, 12 Oct 2010 07:50:59 GMT]]></title><description><![CDATA[<p>du könntest mal nach <code>c++ getopt</code> oder <code>c++ anyoption</code> googeln <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> ich habe beide noch nicht benutzt aber die sind wohl für sowas da</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1964180</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964180</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Tue, 12 Oct 2010 07:50:59 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Konsolenanwendung Argumente überprüfen on Tue, 12 Oct 2010 08:47:22 GMT]]></title><description><![CDATA[<p>Danke für eure Hilfe.. werde mich darüber etwas schlau machen. Jedoch habe ich gemerkt, das das Programm gar nicht richtig läuft.. muss zuerst fertigbringen, dass alles andere läuft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1964206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964206</guid><dc:creator><![CDATA[TTS]]></dc:creator><pubDate>Tue, 12 Oct 2010 08:47:22 GMT</pubDate></item><item><title><![CDATA[Reply to C++ Konsolenanwendung Argumente überprüfen on Tue, 12 Oct 2010 09:18:40 GMT]]></title><description><![CDATA[<p>Ich find <a href="http://www.boost.org/doc/libs/1_44_0/doc/html/program_options/tutorial.html" rel="nofollow">boost::program_options</a> ziemlich cool <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1964242</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964242</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Tue, 12 Oct 2010 09:18:40 GMT</pubDate></item></channel></rss>