C/C++基础
Janton Wang
这个作者很懒,什么都没留下…
展开
-
C/C++基础 (typename)
#include<stdio.h>#include<string.h>#include<vector&am原创 2018-11-13 23:03:37 · 144 阅读 · 0 评论 -
基于TCP协议,简单的网络程序(Linux,C)
代码/* server.c */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/socket.h>#include <netinet/in.h> //IPv4和IPv6的地址格式#d...原创 2019-06-12 22:17:00 · 266 阅读 · 0 评论 -
多个client的交互式请求(Linux,C)
1. 多进程并发处理–fork// wrap.h#include <stdlib.h>#include <errno.h>#include <sys/socket.h>void perr_exit(const char *);int Accept(int, struct sockaddr *, socklen_t *);void Bind(int...原创 2019-06-14 11:24:31 · 228 阅读 · 0 评论 -
UDP协议网络程序(Liunx,C)
//wrap.h#include <stdlib.h>#include <errno.h>#include <sys/socket.h>void perr_exit(const char *);int Accept(int, struct sockaddr *, socklen_t *);void Bind(int, const struct so...原创 2019-06-14 15:22:06 · 287 阅读 · 0 评论 -
waitpid、WIFEXITED、WEXITSTATUS、WIFSIGNALED、WTERMSIG
#include<sys/types.h>#include<sys/wait.h>#include<unistd.h>#include<stdio.h>#include<stdlib.h>#include <assert.h>int main(void){ pid_t pid; pid = fork(); ...原创 2019-06-09 21:28:12 · 2407 阅读 · 0 评论 -
进程间通信无名pipe和有名fifo(Linux,C)
#include <stdlib.h>#include <unistd.h>#define MAXLINE 80int main(void){ int n; int fd[2]; // 管道两端文件描述符,fd[0]读断,fd[1]写段 pid_t pid; char line[MAXLINE]; if (pipe(fd) < 0) { // 创...原创 2019-06-10 14:04:54 · 197 阅读 · 0 评论 -
全面详解sizeof
#include <stdio.h>using namespace std;int main(void){ printf("len_char=%d\nlen_int=%d\nlen_signed_int=%d\nlen_unsigned_int=%d\nlen_short=%d\nlen_long=%d\nlen_float=%d\nlen_double=%d\n", si...原创 2019-06-04 11:16:19 · 310 阅读 · 0 评论 -
linux线程(C)
// pthread.c#include<pthread.h>pthread.cint pthread_create(pthread_t *restrict thread,const pthread_attr_t *restrict attr,void *(*start_routine)(void*), void *restrict arg);// 储存线程号,NULL,要执行...原创 2019-06-11 16:30:43 · 179 阅读 · 0 评论 -
GNU-autotools使用实例(代码)
这里使用走迷宫深度优先搜索,把它写成一个项目。项目的目录树如下:目录树:├── include│ ├── main_tmp.h│ ├── maze.h│ └── stack.h├── lib│ ├── maze.c│ └── stack.c└── src └── main.c内容://main_tmp.h#ifndef MAIN_TMP_H...原创 2019-06-17 23:23:43 · 258 阅读 · 0 评论 -
GNU-autotools使用实例(详解)
├── include│ ├── main_tmp.h│ ├── maze.h│ └── stack.h├── lib│ ├── Makefile.am│ ├── maze.c│ └── stack.c├── Makefile.am└── src ├── main.c └── Makefile.am3个makefile.am详解1)顶...原创 2019-06-18 17:29:44 · 508 阅读 · 0 评论 -
子类和父类之间类型转换
1. 子类 -> 父类父类 -> Base#include<isotream>using namespace std;class Base{public: Base() : pub_att(1){} int pub_att;};public继承的子类1 -> Derived1class Derived1 : public Base{publi...原创 2019-06-26 23:05:58 · 1536 阅读 · 0 评论 -
gdb基本命令
原创 2019-04-22 22:09:43 · 642 阅读 · 0 评论 -
C++ 科学计数法和精度问题
C++ 科学计数法和精度问题(来源于C++入门经典第三版)// Program 2.8 Experimenting with floating point output#include <iostream> // fixed scientific#include <iomanip> // setprecision()using std::setprecision...原创 2019-04-11 21:42:12 · 7028 阅读 · 0 评论 -
C/C++基础 (link)
// other.cppchar c = ':';double get_area(double r) { return 3.14 * r * r;}#include&amp;amp;amp;lt;stdio.h&amp;amp;amp;gt;extern char c;double get_area(double r); // equal to extern double get_area(double );int mai...原创 2018-11-13 23:05:16 · 568 阅读 · 0 评论 -
C/C++基础 (time)
如何才能快速入坑 C/C++?曾经我也是抱着《C++ Primer 中文版》和《Effective C++ 中文版》。但是对于初学者,它们并不是最好的选择,这里推荐《C/C++学习指南》一本非常适合入门的指导书。分享学习时候写的代码。C:\Users\LAILAI\Desktop&amp;amp;gt;g++ --versiong++.exe (GCC) 4.7.0 20111220 (experimenta...原创 2018-11-13 23:06:39 · 186 阅读 · 0 评论 -
C/C++基础 (linkedlist)
#include&amp;amp;amp;amp;amp;amp;lt;stdio.h&amp;amp;amp;amp;amp;amp;gt;#include&amp;amp;amp;amp;amp;amp;lt;string.h&amp;amp;amp;amp;amp;amp;gt;struct Student { int id; char name[16]; Student* next;};Student原创 2018-11-14 13:12:37 · 947 阅读 · 0 评论 -
C/C++基础 (argc, argv[])
//create f_main.exe#include&amp;amp;lt;stdio.h&amp;amp;gt;#include&amp;amp;lt;stdlib.h&amp;amp;gt;#include&amp;amp;lt;math.h&amp;amp;gt;int main(int argc, char* argv[]) { printf(&amp;quot;原创 2018-11-14 13:13:08 · 371 阅读 · 0 评论 -
C/C++基础 (malloc , free)
#include&amp;amp;amp;lt;stdio.h&amp;amp;amp;gt;#include&amp;amp;amp;lt;stdlib.h&amp;amp;amp;gt;int main() { auto p = (char*)malloc(8); for (int i = 0; i &amp;amp;amp;lt; 8; i++) { p[i] = i + 1; } fre原创 2018-11-14 13:13:54 · 562 阅读 · 0 评论 -
C/C++基础 (new, delete)
//class_2.h#ifndef _CLASS_2_H#define _CLASS_2_Hclass Circle {public: Circle() { printf(&amp;amp;quot;ccccc1\n&amp;amp;quot;); m_x = m_y = 0; m_radius = 0; } Circle(int x,int y,int r) { printf(&amp;amp;quot原创 2018-11-14 13:14:24 · 394 阅读 · 0 评论 -
C/C++基础 (struct)
如何才能快速入坑C++?曾经我也是抱着《C++ Primer》《C/C++学习指南》原创 2018-11-14 13:14:58 · 215 阅读 · 0 评论 -
C/C++基础 (file)
int main() {/*const char* filename = “c:\cfiletestC.txt”; // “c:/cfiletest.txt”;FILE* fp = fopen(filename, “wb”);if (fp == NULL) { printf(&amp;amp;amp;amp;quot;failed to open file&amp;amp;amp;amp;quot;); return -1;}int buf原创 2018-11-14 13:15:25 · 262 阅读 · 0 评论 -
C/C++基础 (sstream)
#include<iostream>#include<string>#include<sstream> //stringstreamusing namespace std;int main() { string line; while (getline(cin, line)) { int sum = 0, x; stringstream ss...原创 2018-12-06 22:35:48 · 446 阅读 · 0 评论 -
C/C++基础 (rand)
#include<iostream>#include<vector>#include<cstdlib> // rand()#include<algorithm> // sort()#include <assert.h> // assert()#include<time.h> // clock() CLOCKS_PER...原创 2018-12-09 11:58:27 · 532 阅读 · 0 评论 -
ifstream和istream转型与报错
代码// this.cpp#include<iostream>#include<string>#include<fstream> using namespace std;void print(istream &strm, ifstream &fstrm){ string c; while(getline(strm,c)) {...原创 2019-07-09 11:14:53 · 1672 阅读 · 0 评论