L
Larry
Hi,
I am having problems with the following code:
// mylib.h
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
namespace mylib
{
struct reqline
{
const std::string method;
const std::string uri;
const std::string vprot;
reqline();
reqline(std::string const & line);
};
}
// mylib.cpp
#include "mylib.h"
namespace mylib
{
// reqline
reqline::reqline() : method(""), uri(""), vprot("") {}
reqline::reqline(const std::string & line)
{
std::vector<std::string> vs;
char* token;
const char* delim = " ";
token=strtok((char*)line.c_str(), delim);
while (token != NULL)
{
vs.push_back(std::string(token));
token = strtok(NULL, delim);
}
method = vs[0]; // error
uri = vs[1]; // error
vprot = vs[2]; // error
}
}
// main.cpp
#include <string>
#include "mylib.h"
using namespace mylib;
int main()
{
std::string line = "GET /index.html HTTP/1.1";
reqline rl(line);
(...)
return 0;
}
I would like to have reqline construct set its internal struct by calling it
at runtime with a parameter. Yet. I'm having a problem related maybe to the
fact that I'm not allowd to change a const stringat runtime...I was almost
positive I could set const string in the construction moment though.
what wrong with that?
thanks
I am having problems with the following code:
// mylib.h
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
namespace mylib
{
struct reqline
{
const std::string method;
const std::string uri;
const std::string vprot;
reqline();
reqline(std::string const & line);
};
}
// mylib.cpp
#include "mylib.h"
namespace mylib
{
// reqline
reqline::reqline() : method(""), uri(""), vprot("") {}
reqline::reqline(const std::string & line)
{
std::vector<std::string> vs;
char* token;
const char* delim = " ";
token=strtok((char*)line.c_str(), delim);
while (token != NULL)
{
vs.push_back(std::string(token));
token = strtok(NULL, delim);
}
method = vs[0]; // error
uri = vs[1]; // error
vprot = vs[2]; // error
}
}
// main.cpp
#include <string>
#include "mylib.h"
using namespace mylib;
int main()
{
std::string line = "GET /index.html HTTP/1.1";
reqline rl(line);
(...)
return 0;
}
I would like to have reqline construct set its internal struct by calling it
at runtime with a parameter. Yet. I'm having a problem related maybe to the
fact that I'm not allowd to change a const stringat runtime...I was almost
positive I could set const string in the construction moment though.
what wrong with that?
thanks