我正在尝试向 send() 添加一个插入变量。
这是代码:
string num;
// + num + is the reason for the error. Any work around or suggestions?
char *msg = "GET /index.php?num=" + num + " HTTP/1.1\nhost: domain.com\n\n";
int len;
ssize_t bytes_sent;
len = strlen(msg);
bytes_sent = send(socketfd, msg, len, 0);
我收到错误:
test.cpp: In function âint main()â:
test.cpp:64: error: cannot convert âstd::basic_string<char, std::char_traits<char>,
std::allocator<char> >â to âchar*â in initialization
- 编辑 -
我试图用 msg.c_str 修复它
cout << "send()ing message..." << endl;
string msg = "GET /index.php?num=" + num + " HTTP/1.1\nhost: domain.com\n\n";
int len;
ssize_t bytes_sent;
len = msg.lenght(); //updated to this and still gives me an error.
bytes_sent = send(socketfd, msg.c_str, len, 0);
现在它给了我错误:
error: argument of type âconst char* (std::basic_string<char, std::char_traits<char>,
std::allocator<char> >::)()constâ does not match âconst char*â