MRT
thats mean p is pointer for int type
Anonymous
So?
MRT
it's correct ?
Anonymous
Probably
MRT
std:: string is optional
Anonymous
std:: string is optional
I don't know what do you mean by that
MRT
sorry danya im bad englisj
MRT
I don't know what do you mean by that
how i can get value from pointer ?
Anonymous
If you don't know such basic stuff, read a book
MRT
I started reading the c++ prime 5th
Stefano
Guys what is the best way to parse a file like this: https://pastebin.com/s4LxFNGE
Stefano
To be able to insert each element into a dynamic vector of structures?
Anonymous
To be able to insert each element into a dynamic vector of structures?
Are you allowed to use something like this? https://www.sqlite.org/cintro.html The records would still need to be parsed.
Stefano
I only have these two functions available(https://pastebin.com/8BJtnbPd), I have to do the rest
Anonymous
Then a typedef for suitable struct will be needed (instead of a SQL schema). // Oh.
Stefano
Then a typedef for suitable struct will be needed (instead of a SQL schema). // Oh.
I have a dynamic vector of structures. This is the structure: https://pastebin.com/Yxd1G7PM
Anonymous
Since each line is split by a ':' I would start with a helper function that fgets() a line and then cleaned up fields, returning two pointers (key, val). Other functions can then use key/val pairs, validate string lengths, identify key names etc. The vals will need to be strcpy'd and/or parsed, and the keys discarded after identifying struct field. You would want to make sure no unknown or missing keys occur too. What if the lines came in different orders, make sure whole set received... So some kind of set for that.
Aakash
Int main(){ int a=5, b=0; b = ++a + ++a; printf("%d\n", b); } Why 2 different compilers output different results? 13 and 14?
This is nothing.. “undefined behavior” GCC is doing it wrong with same storage pre/postfix-increment on same statement line; Clang doing all ok & gives correct results. //some compiler internal coding problem with gcc. 🙃
حماد
Hi anyone can tell me about online C++ compiler in which I can code run and save c++ files
Anonymous
Hello, can someone help me? How can I assign the variable in command line parameter? Like this ./program assign-this-to-variable So that variable can be used in the function
MRT
What is the best way to choose an element in vector ? ?
MRT
What is the best way to choose an element in vector ? ?
std::vector<clientSPTR> clientsInHandshake; void checkOnlineUser() { for (auto& client : clientsInHandshake) { (*client).printMYTOKEN(); if ((*client).is_alive())(*client).doSomthing(); } }
Vlad
What do you mean by "choose"?
MRT
What do you mean by "choose"?
i need to select clientSPTR with id
Vlad
i need to select clientSPTR with id
Then you clearly have the wrong container
Vlad
You'd need a map
Bumpy
you know about java group also?
Beyond
bruh you asking in c++ group about java group
Bumpy
i know men haha i search also a Java group :)
Beyond
oops
Beyond
wait i'll dm you
MRT
std::vector<pair<clientSPTR,ID>> clientHandShake; ... vector..(make_pair(xx,yy)) ..
std::map<std::string, std::vector<clientSPTR>> clients; clients[_key].push_back(clientSPTR(new HandShakeThreadClass(*sock)));
Vlad
std::vector<pair<clientSPTR,ID>> clientHandShake; ... vector..(make_pair(xx,yy)) ..
Lookup will be O(N) instead of O(log N) in the std::map or even O(1) in std::unordered_map.
Vlad
Hmm.. but, Unique key VS duplicates :)
std::vector doesn't deal with duplicate keys
Vlad
So to add to it, you'd have to search the whole container whether the key exists or not
MRT
A question has occupied my mind for none-blocking sockets , In this model, the data sockets are always flowing and that while is active Until the client turns off And finally I can sleep this while for a few milliseconds and continue,My question is, do you not use a lot of server resources while it is always running?
MRT
Thanks to the friends who eagerly respond👌🏿
MRT
do you query non blocking socket like while (recv(sd..)? just use blocking socket
u_long iMode = 1; // its mean socket set to none blocking! ioctlsocket(sock, FIONBIO, &iMode);//set client socket to none blocking int ReceiveTimeout = 10000; setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&ReceiveTimeout, sizeof(ReceiveTimeout)); do { printf("Repeat socket recv \n"); socket_res = recv(sock, &buffer[0], buffer.size(), 0); if (socket_res == SOCKET_ERROR) { int _iERR = WSAGetLastError(); if (_iERR == WSAEWOULDBLOCK) { // currently no data available std::cout << "ERR: its not data currently " << std::endl; // wait and try again //Sleep(5000);// wait and repeat continue; } //client CLOSE is_active = false; continue; } else { //std::cout << "its data babe: " << _data << std::endl; _data.append(buffer.cbegin(), buffer.cend()); this->findItemInData(); } continue; } while (is_active);
MRT
why do you need non blocking? use blocking
with non-blocking sockets you could handle a much larger volume of clients: it could scale to hundreds of thousands in a single process - but the code becomes a little bit more complicated
MRT
https://stackoverflow.com/questions/10654286/why-should-i-use-non-blocking-or-blocking-sockets/10654365
Alex
with non-blocking sockets you could handle a much larger volume of clients: it could scale to hundreds of thousands in a single process - but the code becomes a little bit more complicated
for high performance you should preallocate several threads/processes, and balance clients among these workers. in each worker you use type of epoll with lots of sockets
MRT
anyway, your code handles only one socket. so you don`t need non blocking mode
its a socket response , for accept clients i use this CController::ClientController _clients = CController::ClientController(); do { std::cout << "\nSOCKET READY FOR ACCEPT CLIENT\n" << std::endl; SOCKET* cSocket = new INVALID_SOCKET; *cSocket = accept(ListenSocket, NULL, NULL); //*ClientSocket = accept(ListenSocket, NULL, NULL); if (*cSocket == INVALID_SOCKET) { printf("accept failed with this fucking Error: %d\n", WSAGetLastError()); closesocket(ListenSocket); WSACleanup(); return 1; } _clients.addClientsForHandShake(cSocket); //HandShakeThreadClass* _handshake = new HandShakeThreadClass(ClientSocket); // handShakeClients.push_back(handShakePTR(new HandShakeThreadClass(*ClientSocket))); } while (true);
MRT
so you handle one client socket in one thread. you don`t need nonblocking
im new in cpp, thank for your answer and experiance
Alex
im new in cpp, thank for your answer and experiance
this is not about cpp.https://www.amazon.com/UNIX-Network-Programming-Richard-Stevens/dp/0139498761
Kwablå
How do I learn c++ programming with my phone
MRT
How do I learn c++ programming with my phone
download c++ primer book and reading
Kwablå
Thanks
Vlad
Bye*
)))
Nils
/usr/include/c++/10/tuple:1173: candidate function not viable: no known conversion from 'tuple<std::shared_ptr<Pilang3::Evaluation>, bool>' to 'const tuple<bool &, std::shared_ptr<Pilang3::Evaluation> &>' for 1st argument How does that happen using std::tie?
Nils
bool exec; SharedEvaluation evaluation; std::tie(exec, evaluation) = std::get<SharedEvaluationWBool>(arg.data); My code
Nils
nevermind. me noob.
Mj
Write a program that dynamically allocates an array large enough to hold a user- defined number of test scores. Once all the scores are entered, the array should be passed to a function calculates the average score. The program should display averages of scores with appropriate headings. Use pointer notation rather than array notation whenever possible ( help please)
Diego
Also when you want to delete it just delete [] pointerToFirstElement
Diego
Good luck
حماد
why do you not just use like vs or generally an ide?
I use VS Code on my personal laptop but whenever I go to my university library computers there are no IDE's installed and I have to install every time or use an online compiler.. So that's why I wanted a solution
Diego
And about files and projects if you trust your battery life you could also just connect it to your university's network and send your files over a SFTP or something
Diego
Another solution would be to set up a home server and and set up your own "online compiler" and since it's your own, its already your files ...But that's probably not something just anyone would know how to do or, more importantly, have the time to, lmao
Dima
/ban reply to me to get an instant ban
^^^
I'm using code blocks 😅🙂
for which langs using after C++? for rust not possible ?
^^^
I learned c/c++ with beautiful codeblocks want to start over with rust but idk if possible to work with code b's