본문 바로가기

example

std c++ vector 와 sort 사용법 예제 #include #include "iostream" #include #include using namespace std; typedef struct point{int a;char b;} t_pos; bool cmp(t_pos &A, t_pos &B) {return A.b < B.b;} int main(){cout 더보기
STL sort example (c++) with class, struct #include #include #include #include using namespace std; class t_A{public:int a;int b;}; #defineMAX30 t_Ag_AA[3][MAX]; bool comp_A(const t_A& a, const t_A& b) {return a.b < b.b;} void test_A_sort(){t_A* g_A = g_AA[0]; //initfor (int i = 0; i < MAX; i++) {g_A[i].a = i;g_A[i].b = i%7;} sort(g_A, g_A + MAX, comp_A); for (int i = 0; i < MAX; i++) {printf("%d %d\n", g_A[i].a, g_A[i].b);}} ///////////.. 더보기
cpp 의 sort 사용하기 예제 #include #include #include #include using namespace std; bool cmp(int a, int b) { return a 더보기
[JAVA] Reflection 을 이용한 변수명 출력하기 - 예제코드 예를 들면 public class Car { private String model; public String owner; public static final int FOO = 123; public static final int BAR = 456; 이런식으로 숫자값에 대한 정의만 난무한 class 가 있고, 이에 대해서 변수명을 출력할 일이 있다면 (주로 디버깅) 일일이 switch 문이나 if else 를 만드는 일은 곤욕스러운 일이다. 자바에서는아래와 같이 getDeclaredFields 함수를 이용해서 동적으로 123 의 값을 가지고 "FOO" 를 출력하는 일이 가능하다. onLine compile test : https://www.compilejava.net///********************.. 더보기
get pid by process name - example source code (예제 코드) 원문 : https://phoxis.org/2013/09/13/find-process-ids-of-a-running-process-by-name/ 이름으로 pid 를 찾아내는 예제 #include #include #include #include #include #include /* checks if the string is purely an integer * we can do it with `strtol' also */int check_if_number (char *str){ int i; for (i=0; str[i] != '\0'; i++) { if (!isdigit (str[i])) { return 0; } } return 1;} #define MAX_BUF 1024#define PID_LIST_BL.. 더보기
[linux][platform] O_DIRECT file open, read, write example O_DIRECT flag 를 사용한 file open, read, write 예제 입니다. page size 4096 예 맞추어서 read / write 를 해야 합니다. 더보기