자신이 잘 알고 또 사용해온 C언어의 표준함수를 C++에서도 사용가능 할까?
다음 표준함수를 호출하는 예제를 만들되, C++ 헤더를 선언해서 만들어보자!
그리고 아래의 함수들이 최소 1회 이상 호출되어야한다
참고로 이는 C언어에서 <string.h>에 선언되어있다.
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
char * str1 = "ABC";
char * str2 = "DEF";
char str3[50];
cout<<strlen(str1)<<endl;
cout<<strlen(str2)<<endl;
strcpy(str3, str1);
strcat(str3, str2);
cout<<str3<<endl;
if(strcmp(str1, str2)==0)
cout<<"same"<<endl;
else
cout<<"Different"<<endl;
return 0;
}
다음 세 함수를 이용해서 0이상 100미만 난수 5개를 생성하는 예제를 만들되 C++의 헤더를 선언해서 작성하자.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(void)
{
srand(time(NULL));
for(int i=0;i<5;i++)
{
printf("Random number #%d : %d\n",i+1,rand()%100);
}
return 0;
}
Rdmxmx