程序如下: #include <windows.h>
#include <string.h> void LoadExtApp(char *sFileName)
{
char sCmdLine[150];
char sSystemPath[MAX_PATH];
char SText[50];
GetWindowsDirectory(sSystemPath, MAX_PATH);//获取windows目录,如:c:\windows
SText.Format("%s\\notepad.exe %s", sSystemPath, sFileName);//执行notepad.exe
strcpy(sCmdLine, SText);
WinExec(sCmdLine, SW_SHOWDEFAULT);
}
void main()
{
char filename[]={"D:\\data.txt"};
LoadExtApp(filename);
}
错误出现在这行: SText.Format("%s\\notepad.exe %s", sSystemPath, sFileName);//执行notepad.exe
错误是: error C2228: left of '.Format' must have class/struct/union type
#include <string.h> void LoadExtApp(char *sFileName)
{
char sCmdLine[150];
char sSystemPath[MAX_PATH];
char SText[50];
GetWindowsDirectory(sSystemPath, MAX_PATH);//获取windows目录,如:c:\windows
SText.Format("%s\\notepad.exe %s", sSystemPath, sFileName);//执行notepad.exe
strcpy(sCmdLine, SText);
WinExec(sCmdLine, SW_SHOWDEFAULT);
}
void main()
{
char filename[]={"D:\\data.txt"};
LoadExtApp(filename);
}
错误出现在这行: SText.Format("%s\\notepad.exe %s", sSystemPath, sFileName);//执行notepad.exe
错误是: error C2228: left of '.Format' must have class/struct/union type
sprintf(SText, "%s\\notepad.exe %s", sSystemPath, sFileName);
CString SText;
谢谢......
当然,你可以使用sprintf来将所需要的字符串写入。如果是UNICODE版本则使用wsprintf。
具体使用方法参见MSDN。上面有详细叙述
#include <windows.h>
#include <string.h> void LoadExtApp(char *sFileName)
{
char sCmdLine[150];
char sSystemPath[MAX_PATH];
CString SText;
GetWindowsDirectory(sSystemPath, MAX_PATH);//获取windows目录,如:c:\windows
SText.Format("%s\\notepad.exe %s", sSystemPath, sFileName);//执行notepad.exe
strcpy(sCmdLine, SText);
WinExec(sCmdLine, SW_SHOWDEFAULT);
}
void main()
{
char filename[]={"D:\\data.txt"};
LoadExtApp(filename);
}