Time of Update: 2018-07-25
轉載自: http://www.cnblogs.com/kkdd-2013/p/5370094.html C模版35h 1 友元函數和友元類 2 友元函數 友元全域函數 友元成員函數 3 友元函數代碼實踐 4 友元類 5 友元類代碼實踐 6 static 7 靜態代碼實踐 8 運算子多載
Time of Update: 2018-07-25
轉一老外的演算法,不錯很好用,多重副檔名也可以處理,例如 aaa.doc.bak // --- 使用示範 ------------------- if ( FilenameMatch("*.exe", "filename.exe") == 1 ) { // filename.exe 匹配 *.exe 結構 } else { // 不匹配 }
Time of Update: 2018-07-25
C99中已經支援可變數組了,但VC中還不支援,但支援柔性數組(特殊的可變長數組)。 什麼是柔性數組,怎麼使用呢。請看下面代碼。 #include <stdio.h>#include <string.h>#include <malloc.h>///柔性數組////*C99中結構中的最後一個元素允許是未知大小的數組,這就叫做柔性數群組成員,柔性數群組成員前面必須至少一個其他成員。*/typedef struct _FLEX_ARRAY{int
Time of Update: 2018-07-25
#include<stdio.h>int main(){int a = 10;int b = 20;//在c語言中,運算式的結果放在寄存器中//運算式的傳回值 是一個數(a < b ? a : b) = 30; //*(a < b ? a : b) = 30; printf("a=%d,b=%d\n", a, b);return 0;} c語言中:
Time of Update: 2018-07-25
#include <stdio.h> #include <string.h> int main() { char m[555],n[555]; int i,len_m,len_n; int a[555]={0},b[555]={0}; scanf("%s",m); len_m =strlen(m); for(i=0;i<=len_m -1;i++) a[i]=
Time of Update: 2018-07-25
int Day(int year, int month, int day){ int i;int days = 0; int months[12] = {31,0,31,30,31,30,31,31,30,31,30,31}; //判斷某年是否是閏年,看它是否滿足一下2個條件之一(不可能同時滿足) if( (year % 400 == 0) || ( (year % 4 == 0) && ( year % 100 != 0) )
Time of Update: 2018-07-25
原文轉載於:http://blog.csdn.net/zhzht19861011/article/details/5974945,非常感謝。 初學者往往搞不懂如何模組化編程,其實它是簡單易學,而且又是組織良好程式結構行之有效方法之一。 本文將先大概講一下模組化的方法和注意事項,最後將以初學者使用最廣的keil c編譯器為例,給出模組化編程的詳細步驟。 模組化程式設計應該理解以下概述: (1) 模組即是一個.c 檔案和一個.h
Time of Update: 2018-07-25
列印出以下的楊輝三角形(要求列印出10行) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 1 ………… 要求列印出10行 楊輝三角形:端點數為1,每個數等於它肩上兩個數之和。 #include
Time of Update: 2018-07-25
#include <iostream>#include <string.h>#define MAX 13using namespace std;template<typename Type>struct Node{ Type *data; Node *next; Node(const Type *str = "") :data(new Type[strlen(str) + 1]), next(NULL) {
Time of Update: 2018-07-25
檢測是否為迴文字串 C++實現 迴文字串,是一個正讀和反讀都一樣的字串,比如“level”或者“noon”等等就是迴文字串。 檢測原理:定義兩個迭代器,一個指向字串頭部,一個是反向迭代器,指向反向頭部,再逐字比較。 原始碼 #include <iostream>#include <string>using namespace std;bool Test(const string &temp_str) { auto it_b =
Time of Update: 2018-07-25
zz From : http://blog.csdn.net/lanphaday/article/details/6564162 賴勇浩(http://laiyonghao.com) 聲明:本文源自 Danny Kalev 在 2011 年 6 月 21 日發表的《The Biggest Changes in C++11(and Why You Should
Time of Update: 2018-07-25
首先我們知道 const int p 與 int const *p 是一樣的,即 *p 是常量;而 int const p 跟上面是不一樣的,即 p 是常量;我們知道引用只是一個別名,與變數共用儲存空間,並且必須在定義的時候初始化,而且不能再成為別的變數的別名,這讓我們想到什麼呢,貌似跟 int * const p 的性質很像。 其實引用的底層就是用const指標來實現的。下面舉個小例子: #include <iostream>using namespace
Time of Update: 2018-07-25
在C語言中結構體是這樣定義的: union struct{ float a; float b; int c;}data_t;聯合體是這樣定義的: union data{ float a; float b; int c;}data_t;但是他們的功能完全不同~~ 聯合體:“
Time of Update: 2018-07-25
C++ :: STL :: algorithm 1.sort(複雜度O(n*log(n))) 排序演算法無疑是用的最多的演算法之一,下面介紹STL中對於sort的用法: 1.1 普通數組排序,從小到大 如: 對 44 21 44 12 7 23 39 9 22 22 38 23 14 26 47 12 排序sort(a,a + n);//這是對[0,n)區間進行排序預設從小到大sort(a + l,a + r);//這是對[l,r)區間進行排序預設從小到大
Time of Update: 2018-07-25
如果說類是包括C++、Java在內的這些現代程式設計語言必不可少的組成部分的話,那麼,繼承、派生就是和類同生同滅的關係。通過繼承使類和對象適應不斷變化的問題域,儘可能地重複利用已有的類和對象,改造並擴充它們,提高了程式設計的效率。由於成員具有不同的許可權,在繼承時它們的存取權限就會有相應的變化,接下來將一一介紹。 *繼承
Time of Update: 2018-07-25
1、解構函式的定義 解構函式(destructor) 與建構函式相反,當對象結束其生命週期時(例如對象所在的函數已調用完畢),系統自動執行解構函式。解構函式往往用來做“清理善後” 的工作(例如在建立對象時用new開闢了一片記憶體空間,delete會自動調用解構函式後釋放記憶體) C++當中的解構函式格式如下: class <類名>{ public: ~<類名>();};<類名>::~<類名>(){ //函數體};
Time of Update: 2018-07-25
C/C++程式中經常在輸入過程中通過判斷是否輸入斷行符號符來判斷程式是否結束。針對此應用,對存在的若干問題進行說明。 1.樣本程式1——C語言 1.1 程式源碼 輸入一系列未知個數的數字,然後輸出max ,min和average。 #include <iostream>#include <math.h>#include <time.
Time of Update: 2018-07-25
#include <iostream>using namespace std;//把指定的位置為0或者1。int Grial(int x, int n, int flags){ if (flags == 0) { x &= (~(0x1 << (n - 1))); } else { x |= (0x1 << (n - 1)); } return x;}int main(){
Time of Update: 2018-07-25
C語言變長數組之剖析 1、引言 我們知道,與C++等現代程式設計語言不同,傳統上的C語言是不支援變長數組功能的,也就是說數組的長度是在 編譯期就確定下來的,不能在運行期改變。不過,在C99標準中,新增的一項功能就是允許在C語言中使用變 長數組。然而,C99定義的這種變長數組的使用是有限制的,不能像在C++等語言中一樣自由使用。 2、說明 參考文獻[1]中對變長數組的說明如下: C99 gives C programmers the
Time of Update: 2018-07-25
1.引言 C++語言的建立初衷是“a better