编的一个程序COPY文件的,总是出错,不知道是不是输入的格式问题?
#include "stdafx.h"
#include <windows.h>
#include <iostream>using namespace std;
#pragma comment(lib,"msvcrtd.lib")
int _tmain(int argc, _TCHAR* argv[])
{
char SourceFileName[MAX_PATH];
char DestFileName[MAX_PATH];
BOOL Success;
cout << "please input your source file name"<< endl;
cin >> SourceFileName;
cout << SourceFileName<<endl;
cout << "please input your dest file name" << endl;
cin >> DestFileName;
LPCWSTR oldname;
LPCWSTR newname;
oldname = (LPCWSTR)SourceFileName;
newname = (LPCWSTR)DestFileName; Success = CopyFile(oldname,newname,TRUE); if(!Success) cout << "fail to open that file.the error code is "<< GetLastError<< endl; else
cout << "the file copyed is success" << endl; system("PAUSE");
return 0;
}
打开文件总是失败,文件在目录中是存在的
#include "stdafx.h"
#include <windows.h>
#include <iostream>using namespace std;
#pragma comment(lib,"msvcrtd.lib")
int _tmain(int argc, _TCHAR* argv[])
{
char SourceFileName[MAX_PATH];
char DestFileName[MAX_PATH];
BOOL Success;
cout << "please input your source file name"<< endl;
cin >> SourceFileName;
cout << SourceFileName<<endl;
cout << "please input your dest file name" << endl;
cin >> DestFileName;
LPCWSTR oldname;
LPCWSTR newname;
oldname = (LPCWSTR)SourceFileName;
newname = (LPCWSTR)DestFileName; Success = CopyFile(oldname,newname,TRUE); if(!Success) cout << "fail to open that file.the error code is "<< GetLastError<< endl; else
cout << "the file copyed is success" << endl; system("PAUSE");
return 0;
}
打开文件总是失败,文件在目录中是存在的
解决方案 »
- directshow 摄像头采集图像叠加背景
- List box怎样实现每次添加新数据都在第一行显示?
- VC中判断CString中是否含有汉字?
- 关于Use run-time Library 里的 Multithreaded 和Multithreaded DLL的区别
- 谁有自己写的进程外可连接点对象的实现程序
- Release版本下一个比较郁闷的问题!
- 在对话框绘制背景图,对话框启动时为什么会很慢,简直难以忍受?
- 哪里有 像计算器里的数字一样的字体?
- 我想自己画窗体的非客户区,应该捕获哪些Windows消息?
- 究竟是为什么?很奇怪的现象!大家来看看是为什么?50分相送,而且还会增加的或是单独出题加分!分数不成问题,关键是解决问题!
- win2000下怎么键盘空格键(SPACE)的键值是什么?
- 100分急求助:我用SOCKET实现UDP接收,老是丢包,不知道怎么解决,大家帮忙看看这段代码。
LPCTSTR lpExistingFileName, // name of an existing file
LPCTSTR lpNewFileName, // name of new file
BOOL bFailIfExists // operation if file exists
);没说参数是wide char啊
cout << "fail to open that file.the error code is "<< GetLastError<<
我输入时的复制地址D:\\j\\j.exe和D:\\j\\j.exe都不行,程序执行不了复制。
直接
Success = CopyFile(SourceFileName,DestFileName,TRUE);
不行吗?
ocuments and settings\gq\my documents\visual studio 2005\projects\consel\consel\consel.cpp(21) : error C2664: 'CopyFileW' : cannot convert parameter 1 from 'char [260]' to 'LPCWSTR'
你沒有必要使用LPCWSTR,把所有的LPCWSTR換成LPCTSTR就可以了
地址輸入的時候用D:\j\j.exe,不用雙斜綫。
我不清楚你用的編譯器是什麽,在vs2003中LPCWSTR根本就無法轉換為LPCTSTR
错误代码是7C930331应该是文件打不开吧
错误代码是7C930331应该是文件打不开吧
VS2005 默认 unicode 改一下