-
CPP escapes json string
A json string variable is
{
"a": 1,
"b": 2
}
wants to escape as the json string { "a ": 1, "b ", 2}. is a variable, so there is no way to use R "() ". The json library uses jsoncpp is there any good way?
...
-
Why doesn't the line `thread [I] = thread (exec_produce, I + 1) `report an error?
void exec_produce(int duration) {
duration
this_thread::sleep_for(chrono::seconds(duration));
this_thread::get_id()id
cout << "exec_produce thread " << this_thread::get_id()
<< " has sleeped &q...
-
Can unique_ptr return local objects successfully?
unique_ptr < int > test () {
unique_ptr<int> ppp(new int(10));
return ppp;
}
As shown in the code above, ppp can successfully return no error. Ppp is a left value, so it must not be moved, so you have to execute the copy construct...
-
For string types, what's the difference between using push_back and directly concatenating characters with +?
I did a question on leetcode, but for the string type, the push_back concatenation character failed the test, but changed to the plus sign to concatenate the character and passed it. topic link
my two codes:
class Solution {
public:
vector<...
-
What do you think of the readability of the CPP11 program?
recently, I am withholding some CPP11 features and projects. When I see the following code, I feel that the whole person is not good. You know what I feel like when I say "the whole person is bad ". Personally, I think learning new knowledge is a habit...
-
How are the references and const variables in the class before CPP11 initialized?
CPP11 allows list initialization for all objects, and because the constructor body is assigned, references and const variables must be initialized first, so you must use list initialization, so how is it initialized before CPP11? ...
-
On the selection of std::unique_lock and std::lock_guard in CPP11
when I see the conditional variables section of CPP11, I find that all conditional variables are used in conjunction with locks, but at this time they all use unique_lock instead of lock_guard,. Can you explain that? ...
-
Why did the CPP standard library container add cbegin and cend methods?
the standard library container before CPP11 overloaded constant and non-constant object versions for begin and end, and defined cbegin and cend for constant version lines in 11.
11 what is the point of doing this, that is, what is the advantage of suc...
-
Is it possible to understand std::seed_seq? in this way?
when learning < random > library, only seed_seq does not quite understand although I went to MSDN, and cppreference, it is not very clear that there is too little information about seed_seq on Google. my understanding is: when a given seed is not ve...
-
Why not provide semaphores directly in CPP11?
Why not provide semaphores directly in RT,CPP11? Instead, it can be implemented jointly with mutexes and conditional variables, for what consideration? ...
-
Why does control block in shared_ptr maintain weak reference counter??
ref: StackOverflow s question address
The answer explained that weak reference counters have an impact on the life cycle of control block. I understand that new is different from make_shared, but I don t understand why control block needs to maint...
-
How to pass in a class requires a value of the same type in another class?
there is a User class whose method calculate () needs to use a member value in an instance of the external data class as the input source. In the User constructor, you need to pass in different data instances as parameters, and create different User cla...
-
CPP11shared_ptr storage thread
class t
{
public:
vector<shared_ptr<thread> > t1;
public:
t()
{
for (int i = 0; i < 3; iPP)
{
t1.push_back(make_shared<thread>(&t::Func, this)); (1)
}
}
void Func()
...
-
How to calculate the activity of sockfd
this is true. I would like to add a function: the server creates a timer thread to regularly poll to detect sockfd activity, shutting down sockfd that has not been active for a long time but I don t know how to judge whether a sockfd is active or not...
-
Kneeling to answer questions, guessing is an error in the inappropriate use of cPP11 function binding.
well, I wrote a timer with a callback function func
struct Timer
{
std::function<void(int)> func; ---- sockfd
...
Timer(int fd) : clientFd(fd)
{
...
}
};
has a time wheel
class TimeWheel
{
private:
st...
-
Does this program have any problems with exception handling when copying elements?
I tried to use CPP s built-in array as the container at the bottom of the loop queue there is a piece of code to reallocate memory I simplified the code, one of which is as follows
template <typename T, typename Allocator>
inline void Queue<...
-
The Feasibility of converting unique_ptr < T > into T * through reinterpret_cast
projects all use modern CPP,. In principle, they don t have bare pointers. They all use STL smart pointers .
but in the library used, there is a function that asks for a T * *, and unique_ptr itself does not provide a reference to return the encapsula...
-
VS2015 an odbc connection mysql console program, in the project properties-use the unicode character set, return IM002, do not use the successful connection?
An odbc connection mysql program. Use the unicode character set in the project property, return IM002, and connect successfully without using it .
related environment W1064Magi VS2015Mysql8.0
related codes
the connection code using the unicode char...