C command line strings like Java?

Is there any way to get the C string from the command line, just like in Java?

public static void main(String[] args)

Args is an array of C strings?

Solution

It's not accurate, but you can get close to it easily

#include <iostream>
#include <vector>
#include <string>

using namespace std;

typedef vector<string> CommandLineStringArgs;

int main(int argc,char *argv[])
{
    CommandLineStringArgs cmdlineStringArgs(&argv[0],&argv[0 + argc]);

    for (int i = 0; i < cmdlineStringArgs.size(); ++i)
    {
        cout << cmdlineStringArgs[i] << endl;
    }

    return 0;
}

This is just an overloaded constructor using STD:: vector, which uses a start / end iterator pair to copy command-line parameters into the vector It is very similar to Java there

You can use utility methods to build and oppose the vector to convert parameters, but it makes little sense There are also many package processing, interpretation, command line switches, etc. that contain objects Ace, poco, QT, etc. are equipped with such facilities

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>