万仟堂茶具最新款:一个菜鸟的问题,朋友们帮忙呀.

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 13:03:37
我是新手,正学习c/C++/vc,源程序内容:逐行读入文本文件:input.txt,然后调用构造String2Array函数(用来把字符串分割成数据),根据需要把原文本文件中需要的内容显示在屏幕上。
编译不成功呀,错在哪里呀

源代码:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <strstream>
#include <string>
using namespace std;
int main( )
{
string line;
CStringArray sa;
ifstream input("input.txt",ios::in);
strstream temp;
loop: if(input.eof()!=1)
{getline(input,line);
String2Array(line, sa, ',');
cout << a[6]<< endl;
goto loop;}
input.close();
return 0;
}

int String2Array(const CString&s,CStringArray&sa,char chSplitter)
{
int nLen=s.GetLength(),nLastPos,nPos;
bool bContinue;
sa.RemoveAll();
nLastPos=0;
do
{
bContinue=false;
nPos=s.Find(chSplitter,nLastPos);
if(-1!=nPos)
{
sa.Add(s.Mid(nLastPos,nPos-nLastPos));
nLastPos=nPos+1;
if(nLastPos!=nLen) bContinue=true;
}
} while (bContinue);

if (nLastPos!=nLen)
sa.Add(s.Mid(nLastPos, nLen-nLastPos));

return sa.GetSize();
}
错误信息
Compiling...
ld.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\ld\ld.cpp(12) : error C2065: 'CStringArray' : undeclared identifier
Studio\MyProjects\ld\ld.cpp(37) : error C2228: left
C:\Program Files\Microsoft Visual Studio\MyProjects\ld\ld.cpp(45) : error C2228: left of '.Find' must have class/struct/union type
C:\Program Files\Microsoft Visual Studio\MyProjects\ld\ld.cpp(45) : error Studio\MyProjects\ld\ld.cpp(57) : error C2228: left of '.GetSize' must have class/struct/union type
执行 cl.exe 时出错.
ld.obj - 1 error(s), 0 warning(s)

你的程序不支持MFC。。
在建立工程的时候
估计你选的是控制台程序
下一步的时候应该选第四个支持MFC那个
而且你的程序中
String2Array(line, sa, ',');

String2Array(const CString&s,CStringArray&sa,char chSplitter)
参数类型都 不一样
而且函数使用前应该先声明。。。