SKT*_*thy 3 c++ string-literals
此代码基本上与 AMPS 服务器通信并尝试发布主题。
R)的第二个参数的含义是什么publish(?
#include <ampsplusplus.hpp>
#include <iostream>
int main(void)
{
const char* uri = "tcp://127.0.0.1:9007/amps/json";
// Construct a client with the name "examplePublisher".
AMPS::Client ampsClient("examplePublisher");
try
{
// connect to the server and log on
ampsClient.connect(uri);
ampsClient.logon();
// publish a JSON message
ampsClient.publish("messages",
R"({ "message" : "Hello, World!" ,)"
R"(client" : 1 })");
}
catch (const AMPS::AMPSException& e)
{
std::cerr << e.what() << std::endl;
exit(1);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
前缀(可选)
R "delimiter( raw_characters )delimiter"(6) (C++11 起)
原始字符串文字。用于避免转义任何字符。分隔符之间的任何内容都会成为字符串的一部分。prefix,如果存在,具有与上述相同的含义。
例子:
const char* s1 = R"foo(
Hello
World
)foo";
//same as
const char* s2 = "\nHello\nWorld\n";
Run Code Online (Sandbox Code Playgroud)
foo分隔符在哪里。
在你的情况下, amessage将打印:
{ "message" : "Hello, World!" ,client" : 1 }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2900 次 |
| 最近记录: |