#include "stdio.h"
#include "stdlib.h"int main(void)
{
CString array_[7]={
"<KeyWord name=\"#if\" />",
"<KeyWord name=\"#ifdef\" />",
"<KeyWord name=\"#ifndef\" />",
"<KeyWord name=\"#include\" />",
"<KeyWord name=\"#line\" />",
"<KeyWord name=\"#pragma\" />",
"<KeyWord name=\"#undef\" />"
};
CString res = "";
res.Format(array_[6]);
cout<<res<<endl;
int position = res.Find("<KeyWord name=\"");
int position1 = res.Find("\" />",14);
//cout<<"子字符串的位置为(逆向查找)"<<position<<endl; int ch = res.Delete(0,15); cout<<"结果为  "<<res<<endl;
res.TrimRight("\" />");
cout<<"最终结果为  "<<res<<endl; return 0;
}
我都包含了头文件,为什么还是编译出处啊?提示错误如下:-------------------------------------------------------
 error C2065: 'CString' : undeclared identifier
 error C2146: syntax error : missing ';' before identifier 'array_'
 error C2065: 'array_' : undeclared identifier
 error C2109: subscript requires array or pointer type
 error C2059: syntax error : '{'
 error C2143: syntax error : missing ';' before '{'
 error C2143: syntax error : missing ';' before '}'
 error C2146: syntax error : missing ';' before identifier 'res'
 error C2065: 'res' : undeclared identifier
 error C2440: '=' : cannot convert from 'char [1]' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
 error C2228: left of '.Format' must have class/struct/union type
 error C2109: subscript requires array or pointer type
 warning C4552: '<<' : operator has no effect; expected operator with side-effect
  error C2228: left of '.Find' must have class/struct/union type
 error C2228: left of '.Find' must have class/struct/union type
 error C2228: left of '.Delete' must have class/struct/union type
 error C2297: '<<' : illegal, right operand has type 'char [9]'
 error C2228: left of '.TrimRight' must have class/struct/union type
 error C2297: '<<' : illegal, right operand has type 'char [13]'

解决方案 »

  1.   

    哥哥,你要包含正确的头文件啊,,,,,开头加入:#include <iostream.h>
    #include <afx.h>再编译试试?
      

  2.   

    你的项目是不是WIN32控制台?如果是的 你添加了MFC支持没有?
     res.Format(array_[6]) Format的用法不对
      

  3.   

    重新编译后,出错如下:--------------------------------
     
     Linking...
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
    这怎么解决啊
      

  4.   

    void Format( LPCTSTR lpszFormat, ... );void Format( UINT nFormatID, ... );
    http://msdn.microsoft.com/en-us/library/aa314327(v=vs.60).aspx
      

  5.   


    你建的什么工程啊?你这样设置试试:project->setting,然后选中 “General”,在下拉框选择“Use MFC in a Shared DLL”,然后 clean,Rebuild All 试试,
      

  6.   

    一看error   LNK2001就是少加了连接库,编译的时候找不到需要的连接库  project-> setting-> c/c++   -> Project   Options   加入   /MT 或者 project-> setting-> link选项中加入msvcrt.lib库文件
      

  7.   


    哈哈,搞定了,为什么要用MFC 的这些DLL 啊?不用不行么?不过,终于编译没错了,谢谢啦