第一个C++程序
2007-04-12 15:21 | Filed Under C/CPP |
开始学习C++,用惯了java以后觉得这东西真是麻烦。。。
用unicode还挺麻烦的,了解了一下Windows API,学海无涯啊。
- #include <Windows.h>
- #include <string.h>
- #include <iostream>
- using namespace std;
- void ListFile(void);
- int wmain(int argc, TCHAR* argv[]) {
- locale loc ("Chinese-simplified");
- wcout.imbue(loc);
- if (argc > 1) {
- SetCurrentDirectory(argv[1]);
- }
- ListFile();
- return 0;
- }
- void ListFile(void) {
- WIN32_FIND_DATA fd;
- ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
- TCHAR currDir[255];
- ZeroMemory(currDir, 255);
- GetCurrentDirectory(255, currDir);
- HANDLE hFile = FindFirstFile(L"*.*", &fd);
- if (hFile != INVALID_HANDLE_VALUE) {
- do {
- if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- // This is a directory entry. Ignore the “.” and “..” entries.
- if (! (fd.cFileName[0] == '.' && (fd.cFileName[1] == 0 || fd.cFileName[1] == '.'))) {
- SetCurrentDirectory(fd.cFileName);
- wcout << "Directory changed to:" << currDir << "\\" << fd.cFileName << endl;
- ListFile();
- SetCurrentDirectory(currDir);
- wcout << "Directory changed to:" << currDir << endl;
- }
- } else {
- wcout << fd.cFileName << endl;
- }
- } while (FindNextFile(hFile, &fd));
- }
- FindClose(hFile);
- }
相关日志


