我有以下程序,我在命令行中传递了 2 个参数,如下所示。我期待 argc 为 3,但它打印为 6。为什么?
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
void usage();
int main(int argc, char *argv[])
{
cout << argc << endl;
if (argc != 3)
usage();
string regex = argv[1];
string searchString = argv[2];
cout << "regex: " << regex << " . searchString: " << searchString << endl;
return 0;
}
void usage()
{
cout << "Usage: ./stringmatch <regex> <searchString>" << endl;
exit(1);
}
命令行:
[jim@cola c++]$ ./stringmatch [yyyy\d\d\d]* yyyy1234
6
Usage: ./stringmatch <regex> <searchString>