#include <iostream>
#include <stdio.h>
// 형식 : 이영득_2주차_파일예제.zip
const int MAX_FILENAME_SIZE = 20 ;
const int MAX_BUFFER_SIZE = 256 ;
int main(void)
{
TCHAR FileName[MAX_FILENAME_SIZE] ;
TCHAR InputBuffer[MAX_BUFFER_SIZE] ;
::ZeroMemory(FileName, MAX_FILENAME_SIZE* sizeof(TCHAR) ) ;
::ZeroMemory(InputBuffer, MAX_BUFFER_SIZE* sizeof(TCHAR) ) ;
std::cout << "Input File Name: " ;
wscanf(L"%s", FileName) ;
std::cout << std::endl ;
HANDLE hTemp = ::CreateFile(FileName, GENERIC_ALL, 0, NULL, CREATE_NEW, 0, NULL) ;
std::cout << "Input a Sentence to write in the file: " << std::endl ;
wscanf(L"%s", InputBuffer) ;
std::cout << std::endl ;
DWORD nSize = wcslen(InputBuffer) ;
DWORD nResult = 0 ;
::WriteFile (hTemp, InputBuffer, nSize*sizeof(TCHAR), &nResult, NULL) ;
if (nSize != nResult*sizeof(TCHAR))
std::cout << "Error: nSize != nResult" << std::endl ;
// the file will be opend, and printf inside the file
int i ;
std::cin >> i ;
return 0 ;
}
///////////////////
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <locale.h>
// 형식 : 이영득_2주차_파일예제.zip
const int MAX_FILENAME_SIZE = 20 ;
const int MAX_BUFFER_SIZE = 256 ;
int main(void)
{
_wseflocale(LC_ALL, L"korean") ;
TCHAR FileName[MAX_FILENAME_SIZE] ;
TCHAR InputBuffer[MAX_BUFFER_SIZE] ;
::ZeroMemory(FileName, MAX_FILENAME_SIZE* sizeof(TCHAR) ) ;
::ZeroMemory(InputBuffer, MAX_BUFFER_SIZE* sizeof(TCHAR) ) ;
std::cout << "Input File Name: " ;
wscanf(L"%s", FileName) ;
std::cout << std::endl ;
HANDLE hTemp = ::CreateFile(FileName, GENERIC_ALL, 0, NULL, CREATE_NEW, 0, NULL) ;
std::cout << "Input a Sentence to write in the file: " << std::endl ;
wscanf(L"%s", InputBuffer) ;
std::cout << std::endl ;
DWORD nSize = wcslen(InputBuffer) ;
DWORD nResult = 0 ;
::WriteFile (hTemp, InputBuffer, nSize*sizeof(TCHAR), &nResult, NULL) ;
if (nSize != nResult*sizeof(TCHAR))
std::cout << "Error: nSize != nResult" << std::endl ;
// the file will be opend, and printf inside the file
TCHAR ReadBuffer[MAX_BUFFER_SIZE] ;
::ZeroMemory(ReadBuffer, MAX_BUFFER_SIZE*sizeof(TCHAR)) ;
nSize = nSize*2 ;
::ReadFile(hTemp, ReadBuffer, MAX_BUFFER_SIZE*sizeof(TCHAR), &nSize, NULL) ;
if ( nOut < 0 )
std::cout << "Error: nResult<0" << std::endl ;
wprintf(L"the sentence inside the file: \n %s", ReadBuffer) ;
int i ;
std::cin >> i ;
::CloseHandle(hTemp) ;
return 0 ;
}
'old_Coding > C/C++' 카테고리의 다른 글
[C/C++] 문자열 다루기(1) - 초기화 (0) | 2010.12.13 |
---|---|
[STL::Map] Error occured(*) (0) | 2010.03.18 |
[Scrap] Struct SYSTEM_INFO (*) (0) | 2010.01.04 |
[C++] Function Pointer(3) (Solution) (0) | 2009.12.27 |
[C++] Function Pointer(2) (in class & with STL) (0) | 2009.12.27 |