Extracting the parts of a path using Listener and split_path

Sep 20, 2014 at 2:50 PM
Edited Sep 20, 2014 at 2:53 PM
Given the following code
    listener.support(methods::GET, [](http_request request) {
        string_t path;
        string_t host;
        int port;

        std::vector<utility::string_t> splitPath;

        try {

            path = request.relative_uri().path();
            host = request.relative_uri().host();
            port = request.relative_uri().port();

            splitPath = request.relative_uri().split_path(path);

            std::cout << splitPath.at[1] << std::endl;

            request.reply(http::status_codes::OK, U("Request Recieved!!!"));
        }
        catch (std::exception& e) {
            // TODO: log this
            std::cout << e.what() << std::endl;
        }
    });
I am trying to get each entry in the path but the above code does not compile - the following line fails with
error C3867: 'std::vector<utility::string_t,std::allocator<_Ty>>::at': function call missing argument list; use '&std::vector<utility::string_t,std::allocator<_Ty>>::at' to create a pointer to member c:\users\paul\documents\visual studio 2013\projects\dataengine\dataengine\messagelistener.cpp   34  1   DataEngine
and
Error   2   error C2109: subscript requires array or pointer type   c:\users\paul\documents\visual studio 2013\projects\dataengine\dataengine\messagelistener.cpp   34  1   DataEngine
I'm trying to learn C++ at the same time can anyone help?

Thanks in advance
Coordinator
Sep 23, 2014 at 4:32 PM
Hi paulsc,

There isn't any problem with the C++ Rest SDK here. The problem is you are trying to use some combination of both the vector::at and operator[]. You need to choose one. Either do splitpath[0] OR splitpath.at(0). Also not sure if you are aware but std::vector is indexed starting at zero, not one.

Steve