[C++] c++에서 c 표준 함수 호출

dd_ddong·2022년 7월 10일
0

c++

목록 보기
11/38

헤더파일 선언

기본 c 헤더파일 include

#inclued <stdio.h>

c++에서 include

#include <cstdio>

.h를 생략하고 앞에 c를 붙이면 c언어와 대응되는 c++헤더파일이 include된다.

바뀌는 점

  1. 모든 표준함수들이 namespace std안에 선언되어있다.
  2. c언어에 없던 오버로딩이 추가되어있다.

c 표준함수

string 관련

#include <cstring>

int main()
{
	char string[20] = "Hellow";
	char plus[10] = "World";
	int len = std::strlen(string);
	std::strcat(string, plus);
	std::cout << string;
    std::strcpy(string, plus);
    std::cout << string;
}

random

#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
	srand(time(NULL));
    for(int i=0; i<10; i++)
    	cout << rand%100;
}

0개의 댓글