본문 바로가기

C++3

[프로그래밍][c/c++] Copy CString to clipboard. CString 클립보드에 붙여넣기 매번 사용자에게 IP를 입력하도록 요구 받는데, default로 자주 쓰이는 IP는 정해져 있다.미리 클립보드에 붙여넣기를 해두면 입력할때 paste만 하면되니 편할 것 같아서 구글링하여아래와 같이 함수를 만들었다. void copyToClipboard(const CString strText){HGLOBAL h; LPTSTR arr; size_t bytes = (strText.GetLength()+1)*sizeof(TCHAR); h=GlobalAlloc(GMEM_MOVEABLE, bytes); arr=(LPTSTR)GlobalLock(h); ZeroMemory(arr,bytes); _tcscpy_s(arr, strText.GetLength()+1, strText); //strText.ReleaseBuff.. 2016. 9. 13.
[프로그래밍][c++] printf string format %*.*s 코드를 보다가 처음 보는 외계어를 발견했다.예를 들자면,printf("%*.*s", 20, 10, "abcdefghijklmn"); 보기 쉽게 하기위해서 공백(space)를 ^ 로 표현 하겠다.위 예제의 output은 아래와 같다.^^^^^^^^^^abcdefghij즉, '.' 앞의 숫자 20은 전체 폭이고, 뒤의 숫자는 보여질 갯수이다.다르게 표현한다면,printf("%20.10s", "abcdefghijklmn");위와 같이 표현 할 수 있다. 가변적으로 하려면 위와 같이 하면 된다. 몇 가지 exercise를 해보면printf("%*.*d", 20,10, 13);=> ^^^^^^^^^^0000000013 printf("%*.d", 20, 13);=> ^^^^^^^^^^^^^^^^^^13 printf.. 2016. 8. 11.
폴더 안의 모든 파일 목록 가져오기 get list of files in a directory http://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c folder에 경로만 넣어주면 됨. 굳굳#include vector get_all_files_names_within_folder(string folder) { vector names; char search_path[200]; sprintf(search_path, "%s*.*", folder.c_str()); WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile(search_path, &fd); if(hFind != INVALID_HANDLE_VALUE) { do { // read all .. 2015. 7. 15.
반응형