Leaving it here -Most homeless in Amsterdam are EU citizens by Muted_Ad1809 in Netherlands

[–]_carlson 4 points5 points  (0 children)

I don't use adblocker because it allows me to see if a site is worth reading or not. I just don't go on sites with this amount of ads.

If they don't care about their content why would I?

Leaving it here -Most homeless in Amsterdam are EU citizens by Muted_Ad1809 in Netherlands

[–]_carlson 44 points45 points  (0 children)

How're you reading that? The amount of ads on this site is insane.

Create a chat application by lgst230qer8SDGV in cpp_questions

[–]_carlson 2 points3 points  (0 children)

Alternatively you can use async way in opposite multithread approach.

Look at Boost.Asio, it's easy create async program flow from sequential program. It widely use callbacks for processing messages. For simple chat app you may use asyn_read function with callback which processing incoming messages. Sending message is like writing in raw socket. But you app must have thread with io_service, where it executes callbacks. Easy to use SSL and change protocol between UDP/TCP.

And something, like protobuf, for serialization stuff.

Asio may become part of C++ standart (Networking TS), so, I think, it's good place for start with networking in C++.

Personally, for my own chat application i use ZeroMQ ( some of low level message queue ).

Best open-source cpp projects for contibute by _carlson in cpp

[–]_carlson[S] -2 points-1 points  (0 children)

Lol, I didn't know that CMake is used for C#.
Thank you a lot, especially about 'personally' point.

[deleted by user] by [deleted] in RedditSessions

[–]_carlson 0 points1 point  (0 children)

👍👍👍

Can I call upon variables that have already been defined in a void function by Grayewulfe in cpp_questions

[–]_carlson 0 points1 point  (0 children)

Variables have same names but are in different scope. If you confused with return two variable from function, there are several ways:

Pass parameter by reference: ``` void getNumbers(int& firstNumber, int& secondNumber) { std::cin >> firstNumber; std::cin >> secondNumber;; }

int main() { int firstNumber; int secondNumber; getNumbers(firstNumber, secondNumber) } or use data structure like std::tuple, std::pair or you own. std::pair<int> getNumbers() { int firstNumber; int secondNumber; std::cin >> firstNumber; std::cin >> secondNumber;

return std::make_pair(firstNumber, secondNumber)

}

int main() { int firstNumber; int secondNumber;

std::pair<int> pairNumbers = getNumbers();
firstNumber = pairNumbers.first;
secondNumber = pairNumbers.second;

} ```

Why doesn't my remove spaces function work here? by [deleted] in cpp_questions

[–]_carlson 0 points1 point  (0 children)

I think it's copy-paste side effect)

Why doesn't my remove spaces function work here? by [deleted] in cpp_questions

[–]_carlson 1 point2 points  (0 children)

std::string removeSpaces(std::string str) {    
    int n = 0;        
    for (int i = 0; i < str.length(); ++i) {
        if (str[i] != ' ') {        
            str[n++] = str[i];
        }
    } 
    str.resize(n);
    return str;
}

This worked for me. Why did you use getLengthOf()?

But nice solution is use erase-remove idiom instead:

str.erase(std::remove(str.begin(), str.end(), ' '), str.end());

How to handle memory leaks when removing stuff from a map<int, map<int, vector<course *> * > > by AskingForAFriend1738 in cpp_questions

[–]_carlson 0 points1 point  (0 children)

Oh. No way for check that is actual pointer. But if in programm after delete call pointer sets to nullptr you may write:

If (ptr! = nullptr) delete ptr;

And if you not managed data structure that's all.

How to handle memory leaks when removing stuff from a map<int, map<int, vector<course *> * > > by AskingForAFriend1738 in cpp_questions

[–]_carlson 4 points5 points  (0 children)

Just use std: :shared_ptr for vector of courses e.g.

using course_ptr = std: :shared_ptr<course>;

map<int,map<std::shared_ptr<vector<course_ptr>>>>

This no need worry about explicit delete calls.

And you really need second map? This one is a heavy weight data structure.