标签:The use output asi app style mod let logical
1 /* memset example */ 2 #include <stdio.h> 3 #include <string.h> 4 5 int main () 6 { 7 char str[] = "almost every programmer should know memset!"; 8 memset (str,‘-‘,6); 9 puts (str); 10 return 0; 11 }
struct sockaddr_in, struct in_addr
1 #include <netinet/in.h> 2 3 struct sockaddr_in { 4 short sin_family; // e.g. AF_INET 5 unsigned short sin_port; //e.g. htons(3490) 6 struct in_addr sin_addr; // see struct in_addr, below 7 char sin_zero[8]; // zero this if you want to,, actually is a piece of shit,, let it go 8 }; 9 10 struct in_addr { 11 unsigned long s_addr; // load with inet_aton() 12 } 13 //example here-------------------------------------------- 14 struct sockaddr_in myaddr; 15 int s; 16 myaddr.sin_family = AF_INET; 17 myaddr.sin_port = htons(3490); 18 inet_aton("127.0.0.1", &myaddr.sin_addr.s_addr); 19 20 s = socket(PF_INET, SOCK_STREAM, 0); 21 bind(s, (struct sockaddr*)myaddr, sizeof(myaddr));
paddr : Converts a logical pointer into its physical address. This function is compatible with both shared and separate I&D space compile modes.
memcpy:Copies counts bytes from the object pointed to by src to the object pointed to by des. Both objects are reinterpreted as arrays of unsigned char.
#include <iostream> #include <cstdint> #include <cstring> int main() { // simple usage char source[] = "once upon a midnight dreary...", dest[4]; std::memcpy(dest, source, sizeof dest); for (char c : dest) std::cout << c << ‘\n‘; // reinterpreting double d = 0.1; // std::int64_t n = *reinterpret_cast<std::int64_t*>(&d); // aliasing violation std::int64_t n; std::memcpy(&n, &d, sizeof d); // OK std::cout << std::hexfloat << d << " is " << std::hex << n << " as an std::int64_t\n"; }
htonl htonl, htons, ntohl, ntohs - convert values between host and network byte order
my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
String to char
1 p = mess.data(); 2 send_message(p);
3 string str="adcd";
4 char *p=(char*)str.c_str();
sendto send, sendto, sendmsg - send a message on a socket
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
recvfrom recvfrom - receive a message from a socket
#include <sys/socket.h> ssize_t recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct sockaddr *restrict address, socklen_t *restrict address_len);
Get rid of `deprecated conversion from string constant to char* warnings in GCC`
should use char const * as the type instead of char*
By default, Ubuntu system has firewall, When we use UDP to transport data, we need shut down the firewall at first..
1 iptables -P INPUT ACCEPT 2 iptables -P FORWARD ACCEPT 3 iptables -P OUTPUT ACCEPT 4 iptables -F
unsigned char arrary to string
1 unsigned char u_array[4] = { ‘a‘, ‘s‘, ‘d‘, ‘f‘ }; 2 3 #include <string> 4 #include <iostream> 5 #include <ostream> 6 7 int main() 8 { 9 std::string str( u_array, u_array + sizeof u_array / sizeof u_array[0] ); 10 std::cout << str << std::endl; 11 return 0; 12 }
‘inet_ntoa‘ not declared error
1 //From man inet_ntoa it appears you have to define _BSD_SOURCE before including the headers: 2 3 #define _BSD_SOURCE 4 #include <sys/socket.h> 5 #include <netinet/in.h> 6 #include <arpa/inet.h>
string str="adcd";
char *p=(char*)str.c_str();
Problems met when implement Dictionary with C/C++ on Ubuntu
标签:The use output asi app style mod let logical
原文地址:https://www.cnblogs.com/bladewangpro/p/10322591.html