{"id":66,"date":"2010-11-06T08:13:29","date_gmt":"2010-11-06T08:13:29","guid":{"rendered":"http:\/\/nvntung.wordpress.com\/?p=66"},"modified":"2010-11-06T08:13:29","modified_gmt":"2010-11-06T08:13:29","slug":"parsing-c-command-line-arguments","status":"publish","type":"post","link":"https:\/\/www.itersdesktop.com\/fr\/2010\/11\/06\/parsing-c-command-line-arguments\/","title":{"rendered":"Parsing C++ Command-Line Arguments"},"content":{"rendered":"<div>\n<p><strong>Microsoft Specific<\/strong><\/p>\n<p>Microsoft C\/C++ startup code uses the following rules when interpreting arguments given on the operating system command line:<\/p>\n<ul>\n<li>Arguments are delimited by white space, which is either a space or a tab.<\/li>\n<li>The  caret character (^) is not recognized as an escape character or  delimiter. The character is handled completely by the command-line  parser in the operating system before being passed to the argv array in the program.<\/li>\n<li>A string surrounded by double quotation marks (\u00ab\u00a0<em>string<\/em>\u00ab\u00a0)  is interpreted as a single argument, regardless of white space  contained within. A quoted string can be embedded in an argument.<\/li>\n<li>A double quotation mark preceded by a backslash (\u00ab\u00a0) is interpreted as a literal double quotation mark character (\u00ab\u00a0).<\/li>\n<li>Backslashes are interpreted literally, unless they immediately precede a double quotation mark.<\/li>\n<li>If an even number of backslashes is followed by a double quotation mark, one backslash is placed in the argv array for every pair of backslashes, and the double quotation mark is interpreted as a string delimiter.<\/li>\n<li>If an odd number of backslashes is followed by a double quotation mark, one backslash is placed in the argv  array for every pair of backslashes, and the double quotation mark is  \u00ab\u00a0escaped\u00a0\u00bb by the remaining backslash, causing a literal double quotation  mark (\u00ab\u00a0) to be placed in argv.<\/li>\n<\/ul>\n<div><strong>Example<\/strong><\/div>\n<div>\n<p>The following program demonstrates how command-line arguments are passed:<\/p>\n<pre>\/\/ command_line_arguments.cpp\n\/\/ compile with: \/EHsc\n#include &lt;iostream&gt;\n\nusing namespace std;\nint main( int argc,      \/\/ Number of strings in array argv\n          char *argv[],   \/\/ Array of command-line argument strings\n          char *envp[] )  \/\/ Array of environment variable strings\n{\n    int count;\n\n    \/\/ Display each command-line argument.\n    cout &lt;&lt; \"nCommand-line arguments:n\";\n    for( count = 0; count &lt; argc; count++ )\n         cout &lt;&lt; \"  argv[\" &lt;&lt; count &lt;&lt; \"]   \"\n                &lt;&lt; argv[count] &lt;&lt; \"n\";\n}<\/pre>\n<\/div>\n<p>Xem ngu\u1ed3n t\u1ea1i <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/17w5ykft.aspx\" target=\"_blank\">MSDN<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft Specific Microsoft C\/C++ startup code uses the following rules when interpreting arguments given on the operating system command line: Arguments are delimited by white space, which is either a&hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[36,55],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-cpp","tag-argument","tag-command-line"],"_links":{"self":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":0,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itersdesktop.com\/fr\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}