본문 바로가기

string

std::string c++ 활용 예제 #include #include using namespace std; int main(){string str = "my name is"; // 확장str.append(" onegun");cout 더보기
strcmp 함수의 모호한 return value strcmp 함수는 스트링간 포함여부를 찾는데는 사용하기 어렵다. strstr 이나 strchar 를 사용해야 한다.두 string 이 완전히 동일한지만 판단이 용이하다. #include //#include #include #include #include #include #include #include // O_WRONLY#include // strlen() #define BUFF_SIZE 1024 int main(){ const char* standard = "12345"; const char* standard2 = "0123456"; const char* wrong = "a12"; const char* part = "234"; int rst=0; rst = strcmp(standard, standar.. 더보기
[JAVA] Reflection 을 이용한 변수명 출력하기 - 예제코드 예를 들면 public class Car { private String model; public String owner; public static final int FOO = 123; public static final int BAR = 456; 이런식으로 숫자값에 대한 정의만 난무한 class 가 있고, 이에 대해서 변수명을 출력할 일이 있다면 (주로 디버깅) 일일이 switch 문이나 if else 를 만드는 일은 곤욕스러운 일이다. 자바에서는아래와 같이 getDeclaredFields 함수를 이용해서 동적으로 123 의 값을 가지고 "FOO" 를 출력하는 일이 가능하다. onLine compile test : https://www.compilejava.net///********************.. 더보기
헷갈리는 c string 함수들 정리중... strstr은 문자열 중에서 특정 문구를 찾아 그 위치를 반환해 주는 함수특히, 포함된 문자열을 찾는데 유용하다. (strcmp 를 사용하면 안된다 !!) /*strstr */char * strstr(const char * str1, const char * str2); 참조 : http://tapito.tistory.com/313 1. strcat - strcat (string concatenation)은 문자열 2개를 이어 붙이는 역할을 해주는 함수이다. 예컨대, "Love"와 "You"를 합치면 LoveYou가 될 것이다. 이처럼 두개의 문자열을 합쳐주는 함수가 strcat 이다. 이 함수의 사용방법과 내부적인 결과를 자세히 살펴보자. 먼저 함수의 모양을 알아보자. 함수.. 더보기