How to get std :: string from command line arguments in win32 application?

So now I have

int main (int argc, char *argv[]){}

how to make it string? will be int main (int argc, std::string *argv[])enough?

+5
source share
6 answers

If you want to create a string from the passed input parameters, you can also add character pointers to create the string yourself

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[])
{

string passedValue;
for(int i = 1; i < argc; i++)
 passedValue += argv[i];
    // ...
    return 0;
}
+4
source

You cannot change the main signature, so this is your best bet:

#include <string>
#include <vector>

int main(int argc, char* argv[])
{
    std::vector<std::string> params(argv, argv+argc);
    // ...
    return 0;
}
+26
source

, , . , CRT STL, . :

#include <string>
#include <vector>

int main(int argc, char* argv[])
{
    std::vector<std::string> args;
    for(int i(0); i < argc; ++i)
        args.push_back(argv[i]);

    // ...

    return(0);
}; // eo main
+3

, 3.6.1

. . int, . main:

int main() { /* ... */ }

int main(int argc, char* argv[]) { /* ... */ }

+3

. . , char * argv [].

, ++ main return 'int'

+2

main char *. argv std:: strings .

+2

All Articles