顯示具有 C++ 標籤的文章。 顯示所有文章
顯示具有 C++ 標籤的文章。 顯示所有文章

2019年6月5日 星期三

[C++]隨機亂數 用法 rand()

#include <iostream>
#include<stdlib.h>
#include <time.h>


srand(time(NULL));//此行每次都加表示每次都會重新刷新
int tenbuf = int((rand() % 10) + 1);//1~10
int hubuf = int((rand() % 100) + 1);//1~100

測試環境 mfc c++空專案 

2019年5月21日 星期二

[C++]char* to int atoi

C庫函數 int atoi(const char *str) 轉換為字符串參數str為整數(int型)。 

int atoi(const char *str)

str -- 這是一個整數的字符串表示形式。

int val;
char str[20];
strcpy(str, "123456");
val = atoi(str);
//String value = 123456, Int value = 123456
 
strcpy(str, ".net");
val = atoi(str);
//String value = .net, Int value = 0


測試環境: vs 2015 mfc

2019年5月20日 星期一

[c++]讀檔迴圈使用注意feof()

 FILE* pFile;
 while (!feof(pFile)) {
  //fread 讀取
  //資料處理
 }
 //如先使用fread讀取,再來判斷feof,當feof判斷為true時就跳離loop
 while (1) {
  //fread讀取
  if (feof(pFile))
    break;
 }

測試環境 vc 2015 mfc

[c++]開檔讀檔寫檔fopen() fwrite()

//在mfc中使用前請先至Stdafx.h 宣告定義
#define _CRT_SECURE_NO_WARNINGS




---------以下為範例--------------------------

FILE *pFile;
char cbuffer[] = { 'h','e','l' ,'l' ,'o' };
pFile = fopen("hello.txt""w");
if (pFile == NULL)
{
 MessageBox(L"empty");
}
else
{
 fwrite(cbuffer,1, sizeof(cbuffer), pFile);
}
fclose(pFile);


測試環境:2015--mfc



參考以下:
FILE * fopen ( const char * filename, const char * mode );
1    

[SQL]顯示千分位與小數顯示

  CONVERT ( data_type [ ( length ) ] , expression [ , style ] ) CONVERT style參數說明 1  (expression為 money 或 smallmoney型別): 0 : 預設,保留小數位後兩位,並四捨...