ios::nocreate

 C++ 프로그래밍을 공부하던 중, 예제 프로그램을 컴파일하다 다음과 같은 에러를 발견했다.

 Description    Resource    Path    Location    Type
‘nocreat’ is not a member of ‘std::ios’    Config.cpp    /TEMS/src    line 40    C/C++ Problem

 환경은 이클립스 3.5.2 버전이었으며, g++ 버전은 version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 이었다.

 문제의 원인을 찾기 위해 구글링을 해보니 답은 간단했다.

 더이상 ios::nocreate 는 표준 C++ 에서 지원하지 않는다는 것.

http://cboard.cprogramming.com/cplusplus-programming/48548-if-ofstream.html 에서 다음과 같은 답변을 찾았다.

 ios::nocreate was removed from standard c++, you may use ios::in to open
the file for reading, and not create one if it doesn’t exist.
The file shouldn’t be created if you have a standard compliant compiler.
(I think dc++ is)

ios::nocreate 를 쓰고 싶다면 그냥 ios::in 만 사용하면 된다. 🙂

함수 이름을 포인터에 할당하여 사용하기

//      funcPtr.c
//     
//      Copyright 2009 Kim Sung-tae <pchero@MyNote>
//     
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//     
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//     
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.

#include <stdio.h>

#define FUNC1 func1
#define FUNC2 func2

int func1(int intVal1) { return –intVal1; }
int func2(int intVal2) { return –intVal2; }

int runFunc(char* string, int inVal)
{
    int retVal;
    int (*funcPtr)(int retVal);
    funcPtr = string;
    return (*funcPtr)(inVal);
}

int main(int argc, char** argv)
{
    int intVal = 3;
    intVal = runFunc(FUNC2, intVal);
    printf(“After running func2 intVal : %dn”, intVal);
    intVal = runFunc(FUNC1, intVal);
    printf(“After running func1 intVal : %dn”, intVal);
   
    return 0;
}

 함수 이름을 포인터에 할당하여 사용하는 재미있는 프로그램.
 함수들을 필요한 순서대로 만들어 둔 뒤, 포인터를 이용하여 상황에 따라 적절한 함수가 호출되도록 만든다면 상태머신(State machine)프로그램 등 유용하게 사용할 수 있을 것이다.

printf scanf 특수문자 도표

* ESC 문자열과 의미
 

ESC 문자열

ASCII CODE

의 미

n

10

new line : 새로운 줄의 시작

t

9

tab : 커서 또는 프린터 헤드를 tab 만큼 이동

b

8

backspace : 뒤로 한 칸 움직임

r

13

carriage return : 그 줄의 처음으로 이동

f

12

form feed : 프린터의 종이를 다음 페이지로 넘김

a

7

alert : 경고음

v

11

vertical tab

0

null character

\

92

, ‘, “, ?의 문자 상수 사용

39

34

?

63

* Printf()의 변환 문자와 변환 내용

변환 문자

변환 내용

인수 수형

%d

인수를 10진수로 변환

정수형

%o

인수를 8진수로 변환

정수형

%x

인수를 16진수로 변환

정수형

%u

인수를 부호 없는 10진수로 변환

정수형

%c

인수를 한 문자로 변환

정수형(문자형)

%s

인수에 따라 지시되는 문자열로 출력

문자형에 있어서의 포인터형

%f

인수를 float나 double로 받아

부동소수점형의 10진수로 변환 : [-] 00.000000

부동소수점형

%e

인수를 float나 double로 받아

부동소수점형의 10진수로 변환 : [-] 00.000000E [±]00

부동소수점형

%g

%e와 %f 중 변환 문자수가 적은 쪽의 변환 취함

부동소수점형

* Scanf()의 변환 문자와 변환 내용

변환 문자

변환 내용

인수 수형

%c

인수를 한 문자로 변환

정수형(문자형)

%d

인수를 10진수로 변환

정수형

%f

인수를 float형의 10진수로 변환

부동소수점형

%lf, %LF

인수를 double형의 10진수로 변환

부동소수점형

%s

인수에 따라 지시되는 문자열로 출력

문자형에 있어서의 포인터형

출처 : http://cuequedasse.tistory.com/6