帮助老VBasic程序员用简单的文件读取,请:) [英] help old VBasic programmer with simple file read , Please :)

查看:55
本文介绍了帮助老VBasic程序员用简单的文件读取,请:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是一个老程序员,现在爱好者已经使用了cobol,基本和

RPG。

我是c ++的新手,但拥有Microsoft Visual Studio 6.0。


我在Basic中有一个程序读取文件,查找包含特定行的
行字符串,并列出它们。


我试图在C中搜索速度非常好的b / b
大文件。


我有一个程序工作,直到我尝试测试子串。


继承我的代码:


// stimquick.cpp:定义控制台的入口点

应用程序。

//


#include" stdafx.h"

#include< iostream>

#include< fstream>

#include< string>

using namespace std;


char str [] =" Geom";


int main(int argc,char * argv [])

{

字符串行;

char * pdest;

ifstream myfile(" C:\\Documents and Settings \\Owner \\ Myy Documents \

\ downloads \\stimuli\\stimV4wall2.pz2");

if(myfile.is_open())

{

(而!) myfile.eof())

{

getline(myfile,line);

pdest = strstr(line,str);

if(pdest!= NULL)

cout<< line<<结束;

}

myfile.close();

}


其他cout< < 无法打开文件;


返回0;

}

当你停止笑:)可以有人告诉我为什么我得到一个关于

无法在strstr步骤中转换类型的错误。


当我能抓住时,我会得到另一本书一个,但

一个我没有得到很多文件处理。


感谢任何评论。


我怀疑我使用错误的项目类型以及我最终想要做的事情。

Hi all ,

I am an old programmer now hobbyist who has used cobol, basic, and
RPG .
I am new to c++ but have Microsoft Visual Studio 6.0.

I have a program in Basic that reads a file , looks for lines
containing a specific string , and lists them.

I am trying to do the same thing in C in a search for speed with very
large files.

I have a program working until I try testing for the substring.

heres the code I have:

// stimquick.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char str[] = "Geom";

int main(int argc, char* argv[])
{
string line;
char *pdest;
ifstream myfile ("C:\\Documents and Settings\\Owner\\My Documents\
\downloads\\stimuli\\stimV4wall2.pz2");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
pdest = strstr( line, str );
if( pdest != NULL )
cout << line << endl;
}
myfile.close();
}

else cout << "Unable to open file";

return 0;
}
When you stop laughing :) can anyone tell me WHY I get an error about
not being able to convert between types in the strstr step.

I am going to get another book when I can get hold of one , but the
one I have doesnt get much into file handling.

thanks for any comments.

I suspect I am using the wrong project type as well for what I
eventually want to do.

推荐答案

ma*********@yahoo.com 写道:
ma*********@yahoo.com wrote:

大家好,


我是一个老程序员,现在爱好者已经使用了cobol,基本和

RPG。

我是c ++的新手,但拥有Microsoft Visual Studio 6.0。
Hi all ,

I am an old programmer now hobbyist who has used cobol, basic, and
RPG .
I am new to c++ but have Microsoft Visual Studio 6.0.



编译器已过时。它是在C ++之前发布的。

标准化。

That compiler is very out-dated. It was released before C++ was
standardized.


我在Basic中有一个程序读取文件,查找行

包含一个特定的字符串,并列出它们。


我试图在C中搜索速度同样的事情非常好

大文件。


我有一个程序工作,直到我尝试测试子串。


继承我的代码:


// stimquick.cpp:定义控制台的入口点

应用程序。

//


#include" stdafx.h"
I have a program in Basic that reads a file , looks for lines
containing a specific string , and lists them.

I am trying to do the same thing in C in a search for speed with very
large files.

I have a program working until I try testing for the substring.

heres the code I have:

// stimquick.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"



即使名称以std开头,它也是非标准的标题。你的程序不需要

Even through its name starts with "std", it is a non-standard header. It''s
not needed for your program.


#include< iostream>

#include < fstream>

#include< string>

使用命名空间std;


char str [] =" Geom" ;;


int main(int argc,char * argv [])

{

string line;

char * pdest;

ifstream myfile(" C:\\Documents and Settings \\Owner \\\\\\\\\\\\\\\\\\\ b \downloads \\stimuli\\stimV4wall2.pz2");

if(myfile.is_open())

{

while(!myfile.eof())
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char str[] = "Geom";

int main(int argc, char* argv[])
{
string line;
char *pdest;
ifstream myfile ("C:\\Documents and Settings\\Owner\\My Documents\
\downloads\\stimuli\\stimV4wall2.pz2");
if (myfile.is_open())
{
while (! myfile.eof() )



此循环不正确。请参阅C ++ FAQ lite中的问题15.5。

This loop is incorrect. See question 15.5 in the "C++ FAQ lite".


{

getline(myfile,line);

pdest = strstr(line,str);
{
getline (myfile,line);
pdest = strstr( line, str );



为什么你不使用std :: string :: find?

Why aren''t you using std::string::find?


if(pdest != NULL)

cout<< line<<结束;

}

myfile.close();

}


其他cout< < 无法打开文件;


返回0;

}


当你停止笑:)任何人都可以告诉我为什么我得到一个错误关于

无法在strstr步骤中的类型之间进行转换。
if( pdest != NULL )
cout << line << endl;
}
myfile.close();
}

else cout << "Unable to open file";

return 0;
}
When you stop laughing :) can anyone tell me WHY I get an error about
not being able to convert between types in the strstr step.



因为strstr需要一个指向const char的指针,但你给它一个

class std :: string的对象。

Because strstr expects a pointer to const char, but you gave it an object of
class std::string.


我怀疑我使用了错误的项目类型以及我最终想做的事情。
I suspect I am using the wrong project type as well for what I
eventually want to do.



使用line.c_str()作为strstr的第一个参数或使用类似

line.find(str)而不是strstr。

Either use line.c_str() as first argument to strstr or use something like
line.find(str) instead of strstr.


6月13日晚上11:30,Rolf Magnus< ramag ... @ t-online.dewrote:
On Jun 13, 11:30 pm, Rolf Magnus <ramag...@t-online.dewrote:

marks542 ... @ yahoo.com写道:
marks542...@yahoo.com wrote:

大家好,
Hi all ,


我是一个老程序员,现在爱好者已经使用了cobol,基本和

RPG。

我是c +的新手,但拥有Microsoft Visual Studio 6.0。
I am an old programmer now hobbyist who has used cobol, basic, and
RPG .
I am new to c++ but have Microsoft Visual Studio 6.0.



编译器已经过时了。它是在C ++之前发布的。

标准化。


That compiler is very out-dated. It was released before C++ was
standardized.


我在Basic中有一个程序读取文件,查找行

包含特定字符串,并列出它们。
I have a program in Basic that reads a file , looks for lines
containing a specific string , and lists them.


我正在尝试在C中搜索速度非常好的b / b
大文件。
I am trying to do the same thing in C in a search for speed with very
large files.


我有一个程序工作,直到我尝试测试子字符串。
I have a program working until I try testing for the substring.


继承我的代码:
heres the code I have:


// stimquick。 cpp:定义控制台的入口点

应用程序。

//
// stimquick.cpp : Defines the entry point for the console
application.
//


#包括stdafx.h
#include "stdafx.h"



即使名称以std开头,它也是一个非标准的标题。你的程序不需要


Even through its name starts with "std", it is a non-standard header. It''s
not needed for your program.


#include< iostream>

#include < fstream>

#include< string>

using namespace std;
#include <iostream>
#include <fstream>
#include <string>
using namespace std;


char str [] =" Geom" ;;
char str[] = "Geom";


int main(int argc,char * argv [])

{

string line;

char * pdest;

ifstream myfile(" C:\\Documents and Settings \\Owner \\\\ my Documents \

\downloads \\stimuli\\stimV4wall2.pz2");

if(myfile.is_open())

{

while(!myfile.eof())
int main(int argc, char* argv[])
{
string line;
char *pdest;
ifstream myfile ("C:\\Documents and Settings\\Owner\\My Documents\
\downloads\\stimuli\\stimV4wall2.pz2");
if (myfile.is_open())
{
while (! myfile.eof() )



此循环不正确。请参阅C ++ FAQ lite中的问题15.5。


This loop is incorrect. See question 15.5 in the "C++ FAQ lite".


{

getline(myfile,line);

pdest = strstr(line,str);
{
getline (myfile,line);
pdest = strstr( line, str );



为什么你不使用std :: string :: find?


Why aren''t you using std::string::find?


if(pdest != NULL)

cout<< line<< endl;

}

myfile.close();

}
if( pdest != NULL )
cout << line << endl;
}
myfile.close();
}


其他cout<< 无法打开文件;
else cout << "Unable to open file";


返回0;

}
return 0;
}


当你停止笑:)可以有人告诉我为什么我得到一个错误关于

无法在strstr步骤之间转换类型。
When you stop laughing :) can anyone tell me WHY I get an error about
not being able to convert between types in the strstr step.



因为strstr需要一个指向const char的指针,但你给它一个

class std :: string的对象。


Because strstr expects a pointer to const char, but you gave it an object of
class std::string.


我怀疑我使用了错误的项目类型以及我最终想做的事情。
I suspect I am using the wrong project type as well for what I
eventually want to do.



要么使用line.c_str()作为strstr的第一个参数,要么使用类似

line.find(str)而不是strstr。


Either use line.c_str() as first argument to strstr or use something like
line.find(str) instead of strstr.




好​​的非常感谢。


编译器就是我所拥有的:(更新不是一个选项因为

成本。



OK thanks very much.

The compiler is what I have :( updating is not an option for me due to
cost.


ma ********* @ yahoo.com 写道:


请修剪你的回复。
ma*********@yahoo.com wrote:

Please trim your replies.

>


非常感谢。


编译器是我拥有的:(更新不是一个选项我需要支付

费用。
>

OK thanks very much.

The compiler is what I have :( updating is not an option for me due to
cost.



如果您遇到了Windows,那么最新版本的免费版

If you are stuck with windows, there is a free version of the latest M


这篇关于帮助老VBasic程序员用简单的文件读取,请:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆