473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

help old VBasic programmer with simple file read , Please :)

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.

Jun 14 '07 #1
17 1712
ma*********@yahoo.com wrote:
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.
That compiler is very out-dated. It was released before C++ was
standardized.
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"
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;

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() )
This loop is incorrect. See question 15.5 in the "C++ FAQ lite".
{
getline (myfile,line);
pdest = strstr( line, str );
Why aren't you using std::string::find?
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.
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.
Either use line.c_str() as first argument to strstr or use something like
line.find(str) instead of strstr.

Jun 14 '07 #2
On Jun 13, 11:30 pm, Rolf Magnus <ramag...@t-online.dewrote:
marks542...@yahoo.com wrote:
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.

That compiler is very out-dated. It was released before C++ was
standardized.
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"

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;
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() )

This loop is incorrect. See question 15.5 in the "C++ FAQ lite".
{
getline (myfile,line);
pdest = strstr( line, str );

Why aren't you using std::string::find?
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.

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.

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.
Jun 14 '07 #3
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.
If you are stuck with windows, there is a free version of the latest M$
compiler, as well as other free compilers you can use.
--
Ian Collins.
Jun 14 '07 #4

"marks542004 aatt yahoo dott com" wrote:
The compiler is what I have. :( Updating is not an option
for me due to cost.
Get Microsoft Visual Studio 2005 Express Edition:

http://msdn.microsoft.com/vstudio/express/downloads/

It's FREE, and is much more up-to-date then Visual Studio 6.0.
That old thing is a dinosaur. (I should know, I used it at work
2002-2005.)

--
Cheers,
Robbie Hatley
lone wolf aatt well dott com
triple-dubya dott Tustin Free Zone dott org
Jun 14 '07 #5
On Jun 14, 6:30 am, Rolf Magnus <ramag...@t-online.dewrote:
marks542...@yahoo.com wrote:
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.
If speed is a criteria, you may have to write your own. None of
the standard library functions will do a BM search, for example.
I have a program working until I try testing for the substring.
heres the code I have:
[...]
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() )
This loop is incorrect. See question 15.5 in the "C++ FAQ lite".
{
getline (myfile,line);
pdest = strstr( line, str );
Why aren't you using std::string::find?
Or std::search. I'd declare the search string as an std::string
as well, and merge this and the following line into something
like:

if ( std::search( line.begin(), line.end(), str.begin(),
str.end() )
!= line.end() ) {
// ...
}

Somehow, it seems more idiomatic.

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 14 '07 #6
On Jun 14, 8:30 am, Rolf Magnus <ramag...@t-online.dewrote:
#include "stdafx.h"

Even through its name starts with "std", it is a non-standard header. It's
not needed for your program.
this line is microsoft specific and nescesary for correct compilation
of projects on VS family of C++ compilers.Such extententions can be
faced on some platforms.note that "stdafx.h" is double-quated("") not
braced(<>),this means that it is part of project not library .

regards,
FM

Jun 14 '07 #7
On 14 Jun, 10:11, terminator <farid.mehr...@gmail.comwrote:
On Jun 14, 8:30 am, Rolf Magnus <ramag...@t-online.dewrote:
#include "stdafx.h"
Even through its name starts with "std", it is a non-standard header. It's
not needed for your program.

this line is microsoft specific
Which means it shouldn't be posted here. Anyone wanting to help with
the problem needs to be able to copy and paste directly from the
message into their editor and compile the code. That's not possible if
the code includes a non-standard header and the contents of that
header aren't posted. More generally, it's not possible if any
platform-specific extensions are in the code.
and nescesary for correct compilation
of projects on VS family of C++ compilers.
It's not necessary at all. I write C++ programs all the time without
stdafx.h and MS Visual Studio has no problem compiling them for me.

Gavin Deane

Jun 14 '07 #8
On 14 Juni, 11:11, terminator <farid.mehr...@gmail.comwrote:
On Jun 14, 8:30 am, Rolf Magnus <ramag...@t-online.dewrote:
#include "stdafx.h"
Even through its name starts with "std", it is a non-standard header. It's
not needed for your program.

this line is microsoft specific and nescesary for correct compilation
of projects on VS family of C++ compilers.Such extententions can be
faced on some platforms.note that "stdafx.h" is double-quated("") not
braced(<>),this means that it is part of project not library .
Hardly necessary (at least not on VC++ 2005), but if you delete the
file you'll also have to turn or precompiled headers.

--
Erik Wikström

Jun 14 '07 #9
Rolf Magnus wrote:
ma*********@yahoo.com wrote:
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.

That compiler is very out-dated. It was released before C++ was
standardized.
I don't think that's quite true. It supports almost every modern C++
feature, including namespaces, the full standard library, the standard
headers, etc. If it was pre-standard, then it was barely so, likely
working from a draft standard.

There are few well-known problems, including the stupid scoping problem
with for loops, and some sort of template concern (I don't recall the
details) but on the whole it's a reasonable solution.

Naturally, if one can use a better one, then that's the way to go.


Brian
Jun 14 '07 #10
terminator wrote:
On Jun 14, 8:30 am, Rolf Magnus <ramag...@t-online.dewrote:
#include "stdafx.h"
Even through its name starts with "std", it is a non-standard
header. It's not needed for your program.

this line is microsoft specific and nescesary for correct compilation
of projects on VS family of C++ compilers.
This is not true at all (well, the MS specific part is). I've been
working with VS6 for many years, projects small to vast, and never once
used it.


Brian
Jun 14 '07 #11
On Jun 14, 11:11 am, terminator <farid.mehr...@gmail.comwrote:
On Jun 14, 8:30 am, Rolf Magnus <ramag...@t-online.dewrote:
#include "stdafx.h"
Even through its name starts with "std", it is a non-standard header. It's
not needed for your program.
this line is microsoft specific and nescesary for correct compilation
of projects on VS family of C++ compilers.
It's not required by the version of VC++ that's present in the
free Visual Studios 2005, and it wasn't necessary in VC++ 6.0
when I last used it (some five or six years ago).
Such extententions can be
faced on some platforms.note that "stdafx.h" is double-quated("") not
braced(<>),this means that it is part of project not library .
It means that it is not provided by the implementation. If it's
something you wrote, you should provide it for us, so we can see
what you put in it.

Note that implementations do provide non-standard headers. Or
"other-standard" headers:-); on my system, I often use
<unistd.h>, which can't really be called "non-standard", since
it is defined in the Posix standard. But it's not C++ standard,
and I don't post code using it here, except as an example in
special cases (and then explicitly saying that it is system
dependant). Under Windows, I would consider <windows.han
implementation header, to be included using <...>, and not
"...". For that matter, I consider Sybase or Oracle part of my
"implementation", and include their headers using <...as well,
and would do the same thing for many other third party librarys:
Boost especially, but also things like wxWidgets.

--
James Kanze (GABI Software, from CAI) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 15 '07 #12
On Jun 14, 10:18 pm, "Default User" <defaultuse...@yahoo.comwrote:
Rolf Magnus wrote:
marks542...@yahoo.com wrote:
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.
That compiler is very out-dated. It was released before C++ was
standardized.

I don't think that's quite true. It supports almost every modern C++
feature, including namespaces, the full standard library, the standard
headers, etc. If it was pre-standard, then it was barely so, likely
working from a draft standard.

There are few well-known problems, including the stupid scoping problem
with for loops, and some sort of template concern (I don't recall the
details) but on the whole it's a reasonable solution.

Naturally, if one can use a better one, then that's the way to go.

Brian
partial specialization is incomplete and recursive templates are not
supported on VS.net 7 which is newer and I guess VS 6 also behaves
none-std on temporaries to references.So ,it is certainly outdated.

regards,
FM.

Jun 16 '07 #13
On Jun 14, 10:21 pm, "Default User" <defaultuse...@yahoo.comwrote:
terminator wrote:
On Jun 14, 8:30 am, Rolf Magnus <ramag...@t-online.dewrote:
#include "stdafx.h"
Even through its name starts with "std", it is a non-standard
header. It's not needed for your program.
this line is microsoft specific and nescesary for correct compilation
of projects on VS family of C++ compilers.

This is not true at all (well, the MS specific part is). I've been
working with VS6 for many years, projects small to vast, and never once
used it.

Brian
it generates errors on some cases.but using empty solutions it is not
nessesary.
regards,
FM.

Jun 16 '07 #14
On Jun 15, 1:12 pm, James Kanze <james.ka...@gmail.comwrote:
On Jun 14, 11:11 am, terminator <farid.mehr...@gmail.comwrote:
On Jun 14, 8:30 am, Rolf Magnus <ramag...@t-online.dewrote:
#include "stdafx.h"
Even through its name starts with "std", it is a non-standard header.It's
not needed for your program.
this line is microsoft specific and nescesary for correct compilation
of projects on VS family of C++ compilers.

It's not required by the version of VC++ that's present in the
free Visual Studios 2005, and it wasn't necessary in VC++ 6.0
when I last used it (some five or six years ago).
Such extententions can be
faced on some platforms.note that "stdafx.h" is double-quated("") not
braced(<>),this means that it is part of project not library .

It means that it is not provided by the implementation. If it's
something you wrote, you should provide it for us, so we can see
what you put in it.

Note that implementations do provide non-standard headers. Or
"other-standard" headers:-); on my system, I often use
<unistd.h>, which can't really be called "non-standard", since
it is defined in the Posix standard. But it's not C++ standard,
and I don't post code using it here, except as an example in
special cases (and then explicitly saying that it is system
dependant). Under Windows, I would consider <windows.han
implementation header, to be included using <...>, and not
"...". For that matter, I consider Sybase or Oracle part of my
"implementation", and include their headers using <...as well,
and would do the same thing for many other third party librarys:
Boost especially, but also things like wxWidgets.

--
James Kanze (GABI Software, from CAI) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
microsoft project generator wizards often generate a pair of stdafx
cpp and header files per project which usualy contain information on
headers related to the application type to be generated.I have faced
errors about pre-compiled headers omiting stdafx.h . but this is not
nessesary for all programs.

regards,
FM

Jun 16 '07 #15
On Sat, 16 Jun 2007 12:47:29 -0700, terminator wrote:

[stdafx.h]
>It's not required by the version of VC++ that's present in the
free Visual Studios 2005, and it wasn't necessary in VC++ 6.0
when I last used it (some five or six years ago).
[...]
>microsoft project generator wizards often generate a pair of stdafx
cpp and header files per project which usualy contain information on
headers related to the application type to be generated.I have faced
errors about pre-compiled headers omiting stdafx.h . but this is not
nessesary for all programs.
<off-topic>
Because you have not read the documentation on the precompiled headers
feature.
</off-topic>

Please, check how to quote properly, e.g. at
<http://www.usenet.org.uk/ukpost.html>.

--
Gennaro Prota -- Need C++ expertise? I'm available
https://sourceforge.net/projects/breeze/
(replace 'address' with 'name.surname' to mail)
Jun 17 '07 #16
On Fri, 15 Jun 2007 09:12:52 -0000, James Kanze wrote:
>Under Windows, I would consider <windows.han
implementation header, to be included using <...>, and not
"...". For that matter, I consider Sybase or Oracle part of my
"implementation", and include their headers using <...as well,
and would do the same thing for many other third party librarys:
Boost especially, but also things like wxWidgets.
Do you really would use the <form for Boost and wxWidgets, or was it
a typo? BTW, but I think you know already, a core issue was opened
about this

<http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#370>

(the DR was in effect born from a Boost list discussion)

--
Gennaro Prota -- Need C++ expertise? I'm available
https://sourceforge.net/projects/breeze/
(replace 'address' with 'name.surname' to mail)
Jun 17 '07 #17
On Jun 17, 7:27 am, Gennaro Prota <addr...@yahoo.comwrote:
On Fri, 15 Jun 2007 09:12:52 -0000, James Kanze wrote:
Under Windows, I would consider <windows.han
implementation header, to be included using <...>, and not
"...". For that matter, I consider Sybase or Oracle part of my
"implementation", and include their headers using <...as well,
and would do the same thing for many other third party librarys:
Boost especially, but also things like wxWidgets.
Do you really would use the <form for Boost and wxWidgets, or was it
a typo?
It would really depend on the context, but most of the time, I
think, yes. Each application establishes its "implementation":
the compiler/versions, and the various libraries, etc. that it
uses. If Boost or wxWidgets is one of those libraries, then it
gets the <form of include. And if it's not, I probably won't
be allowed to use it.
BTW, but I think you know already, a core issue was opened
about this
<http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#370>
(the DR was in effect born from a Boost list discussion)
I wasn't familiar with the DR, but I see one comment in it with
which I disagree with already: "Existing practice varies
widely". There are some variants, but in practice, I've never
seen nor heard of a compiler which didn't look for <...>
includes starting in the include path specified by the compiler
options.

Note that this in NOT covered by the standard. It's a quality
of implementation issue. As far as the standard is concerned,
there's not even a requirement to allow non-standard includes to
be anywhere but in the current directory, regardless of how they
are included. Whether you use "..." or <...really doesn't
change much here, either from a standards point of view (it's
implementation defined) or from a practical one (the compiler
won't automatically look in the directory containing the source
file with "..."). It does make a difference with regards to the
message you are giving the reader: is this include part of the
application, or at least specific to the company, or is it part
of something he should more or less know from general C++
culture. If you see #include "abc.hh", you look in your
company's documentation to find out about it, if you see
<abc.hh>, you go to the Internet.

Note that the note added to the standard text pretty much agrees
with my position: "In general programmers should use the < >
form for headers provided with the implementation, and the " "
form for sources outside the control of the implementation."
With the note that I use a very broad definition of
"implementation"; it's what is furnished by outside sources.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 17 '07 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: terry | last post by:
I am a programmer (cobol, peoplesoft, sqr, etc.) so I am familiar with programming logic, etc. but not very familiar with C. I need a C program in a study I'm doing. The program is fairly simple,...
4
by: Tad Johnson | last post by:
Hi all, I would not normally post about this issue but after a few hours of struggling maybe it's time for some help. I am a pascal programmer moving to C++. I am learning from a couple of...
3
by: JGBNS via DotNetMonster.com | last post by:
Hi, I am new to this forumand I apologize as i am not a .net programmer but we have a program being developed by a .net programmer. Nowwe have run into an ftp snag and I think it is part ftp and...
9
by: terry | last post by:
I am a programmer (cobol, peoplesoft, sqr, etc.) so I am familiar with programming logic, etc. but not very familiar with C. I need a C program in a study I'm doing. The program is fairly simple,...
15
by: Buck Rogers | last post by:
Hi guys! Task 1: Write a program which presents a menu with 5 options. The 5th option quits the program. Each option should execute a system command using system(). Below is my humble...
11
by: MOOVBUFF | last post by:
I've been looking (wasting my time) for simple solutions such as Updating a database in VS 2005 and all I get is either no answer or another question. Obviously the people in the newsgroup can't...
5
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.