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*â