程序如下: #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

解决方案 »

  1.   

    #include <stdio.h>
    sprintf(SText, "%s\\notepad.exe %s", sSystemPath, sFileName);
      

  2.   

    分配sText的空间会不会太小?
      

  3.   

    要么定义SText为CString;
    CString SText;  
      

  4.   

    liuzxchina 的解正确
    谢谢......
      

  5.   

    你做的是控制台win32程序,普通的内置类型char并不提供Format这个方法。而CString类提供这个方法。
    当然,你可以使用sprintf来将所需要的字符串写入。如果是UNICODE版本则使用wsprintf。
    具体使用方法参见MSDN。上面有详细叙述
      

  6.   

    #include <afx.h>
    #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);
      }