Time of Update: 2018-12-04
本來以為是和java一樣寫法。結果找了半天也沒找到。原來有靜態建構函式一樣的功能。class SimpleClass{ // Static constructor static SimpleClass() { //...
Time of Update: 2018-12-04
deque 就是雙向隊列。對於deque的主要操作有:(constructor)Construct deque container (public member function) //構造 deque格式 deque<int > d; operator=Copy container content (public member function)//可以容器之間進行賦值。例: deque<int> d1(4,100),d2; d2=d1; //d2
Time of Update: 2018-12-04
首先明確一點:系統已經提供了預設的 拷貝建構函式 和 =複製運算子。 即所謂的淺拷貝。但有時,我們必須提供自己重寫。一般是在有指標的情況下重寫。舉個簡單的例子,沒有指標,其實不必重寫,只是為了示範:class Fraction{private:int fenmu; //分母int fenzi; //分子public:Fraction(int x,int y){fenzi = x;fenmu = y;}Fraction(){}Fraction(const Fraction &
Time of Update: 2018-12-04
map的模板定義第三個參數,即為我們的定序。預設是試用std::less<>排序的,對key排序,而不是value。如果我們想對key (string)不區分大小寫進行排序,可以這樣寫。#include "stdafx.h"#include <cctype>#include <map>#include <algorithm>#include <string>#include <iostream>using
Time of Update: 2018-12-04
委託是一種安全地封裝方法的類型,它與 C 和 C++ 中的函數指標類似。與 C 中的函數指標不同,委託是物件導向的、型別安全的和保險的。委託的類型由委託的名稱定義。下面的樣本聲明了一個名為 Del 的委託,該委託可以封裝一個採用字串作為參數並返回 void 的方法。public delegate void Del(string
Time of Update: 2018-12-04
1.首先在c#建立項目-》類庫,添加檔案OperteDataBase.cs和Cache.cs代碼如下檔案OperteDataBase.csusing System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.Sql;using System.Data.SqlClient;using System.Configuration;using
Time of Update: 2018-12-04
剛剛接觸C#,據說C#的異常處理很耗費效能。於是來做個測試。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics;namespace ConsoleApplication2{ class Program { static void Main(string[] args) {
Time of Update: 2018-12-04
////題目描述://輸入一系列整數,建立二叉排序數,並進行前序,中序,後序遍曆。//輸入://輸入第一行包括一個整數n(1<=n<=100)。//接下來的一行包括n個整數。//輸出://可能有多組測試資料,對於每組資料,將題目所給資料建立一個二叉排序樹,並對二叉排序樹進行前序、中序和後序遍曆。//每種遍曆結果輸出一行。每行最後一個資料之後有一個空格。//範例輸入://5//1 6 5 9 8//範例輸出://1 6 5 9 8 //1 5 6 8 9 //5 8 9 6 1
Time of Update: 2018-12-04
一:分析如下代碼char* toStr(int num){char s[100];int i = 0;while(num > 0){s[i++] = num % 10 + '0';//記住為什麼+'0'num /= 10;}s[i] = '\0';return s;}本意為將整數轉化成字元數組儲存,然後將這個字元數組返回。經艱苦實踐,發現不能,原因是指標s是局部變數,當函數返回時s即銷毀,當然不會返回成功了,只能把一個無意義的地址傳回去。所以正確的處理方法可以這樣。void
Time of Update: 2018-12-04
正如Effective C++所講:C++就是一個語言聯邦。他是一個多面手。對於同一個問題往往有很多種解決辦法,具體採用那種辦法就交給程式員去選擇。因此本文對C++檔案IO的整理就得分為兩個面:C方式,C++方式。程式員可根據自己所在團隊選擇合適且統一的IO方式。 一.
Time of Update: 2018-12-04
在物件導向技術下類中成員的可見度以及存取控制程度總是讓程式員發懵。特別是初學者。下面將對其做一總結。1.橫向來看,比較簡單。類中成員的存取控制程度有三種:public,private,proteced。public:完全向外部公開。protected:類中以及衍生類別均可訪問,不能再類外訪問。private:
Time of Update: 2018-12-04
C++中string類的成員函數find_first_not_of()函數原型: #include <string> size_type find_first_not_of(const string &str,size_type index =0 )const; size_type find_first_not_of(const Char* str,size_type index =0 )const; size_type find_first_not_of(co
Time of Update: 2018-12-04
bitset就是可以存放二進位的容器。對於bitset的主要操作有:(constructor)Construct bitset (public member function) //構造bitset.. 格式 bitset<長度> 名字applicable operatorsBitset operators (functions) //可以直接對bitset容器進行二進位操作,如
Time of Update: 2018-12-04
以下所介紹的所有排序都是從小到大排序快速排序的庫函數都包含在標頭檔名為<stdlib.h>中<1>對int型數組排序int num[100];int cmp(const void *a,const void *b){ return *(int *)a-*(int *)b;}int main(){ ...... qsort(num,100,sizeof(num[0]),cmp); return
Time of Update: 2018-12-04
//C++ 二進位位元運算判斷奇數偶數,二進位取位操作,取二進位末位#include<iostream>using namespace std;void main(){int i;for(i=0;i<100;++i){if(1==(1&i))cout<<i<<"是奇數"<<endl;elsecout<<i<<"是偶數"<<endl;}}/*--例如一個數
Time of Update: 2018-12-04
map守C++的一個標準容器,它提供了很好的一對一的關係,在一些程式中建立一個map可以起到事半功倍的效果。Member functions(constructor)Construct map (public member function) //構造,形如 map<int,int >mm;(destructor)Map destructor (public member function) operator=Copy container content (
Time of Update: 2018-12-04
大家都知道,一個類的私人成員只能在他的內部訪問!但是不知道大家注意到沒有,實際上在C#中一個類的執行個體是可以訪問同一個類的另外一個執行個體的私人成員的。請看這段簡單的代碼public class MyClass { private int i = 0; public void Function() { MyClass a = new MyClass(); Console.WriteLine( a.i);
Time of Update: 2018-12-04
前幾天網友問我c++裡面的vector的使用,現在對vector進行簡單總結,共用CSDN網友。說明:東西比較簡單,如果你很牛,請直接關閉本頁!首先是vector的聲明:#include <vector>using namespace std; // 在這裡聲明...vector<int> i;... 或者#include <vector>...std::vector<int> i; // 在這裡顯式聲明看具體使用:1.vector
Time of Update: 2018-12-04
在網上看到一段代碼,覺得有意思,就修改了下共用CSDN讀友。程式運行介面:在看代碼: private void printDramC(Graphics g) { const int MID = 150; const int Top = 50; this.Text = "simple graphics snowman"; Font font = new Font("隸書",17);
Time of Update: 2018-12-04
C#匯入DLL時,參數怎麼定義是一個比較頭痛的問題。特別是指標類型的參數,關於此問題本人有點不成熟的經驗。以 GetComputerName這個函數為例。函數原型如下:BOOL GetComputerName( LPTSTR lpBuffer, LPDWORD lpnSize);這個lpBuffer就是下個string型的指標,其實無論是什麼類型的指標,對於Windows來說都是一個32位的無符號的整數,也就是一個內在地址,函數之所以使用指標就是要向指標所指向的記憶體空間寫入資料。我們用C#