I just found that my fin stream is not getting passed to my
readInASpinnerbait function. Here's what I have:
string readInFirstChars(ifstream &fin)
{
char first[2];
string print;
while (fin.good())
{
fin.get(first, 4, '/');
if (strcmp(first, "sp")==0) {
cout << first << endl; // debugging: outputs 'sp'
string print = "spinnerbait";
readInASpinnerbait(fin); // fin not getting passed
fin.ignore(80, '\n');
return print;
}
}
return 0; }
void readInASpinnerbait(ifstream &fin)
{
cout << "it should read 'sp' right after this" << endl; //it doesn't
char first[2];
string print;
fin.get(first, 4, '/');
cout << first << endl;
// debugging: it doesn't output 'sp'...so fin is not getting
passed.
Spinnerbait spinnerbaitLure;
SpinnerbaitList spinList;
spinnerbaitLure.inputSpinnerbait(fin);
while (!fin.fail()) {
spinList.insertSpinnerbait(spinnerbaitLure, 0);
spinnerbaitLure.inputSpinnerbait(fin);
}
}
I don't understand why fin wouldn't be getting passed here. This seems
simple enough. On a whim, I even tried changing that to istream &sin.
No go. I'd appreciate ANY input. Thanks!
Frank 5 1868
Francis Bell <ph**********@charter.net> wrote in news:10b1l5rcmnijvd6
@corp.supernews.com: I just found that my fin stream is not getting passed to my readInASpinnerbait function. Here's what I have:
What do you mean by "not getting passed"? Do you mean, that the argument
'sinks' between the function call?
The problem lies in the code you haven't posted, I suppose.
Cheers.
"Francis Bell" <ph**********@charter.net> wrote in message
news:10*************@corp.supernews.com... I just found that my fin stream is not getting passed to my readInASpinnerbait function. Here's what I have:
string readInFirstChars(ifstream &fin) { char first[2];
char first[4];
string print; while (fin.good()) { fin.get(first, 4, '/');
You are reading upto four characters in here, so you must declare first as
having four characters.
if (strcmp(first, "sp")==0) { cout << first << endl; // debugging: outputs 'sp' string print = "spinnerbait"; readInASpinnerbait(fin); // fin not getting passed fin.ignore(80, '\n'); return print; } } return 0; }
void readInASpinnerbait(ifstream &fin) { cout << "it should read 'sp' right after this" << endl; //it doesn't char first[2];
Ditto, char first[4];
string print; fin.get(first, 4, '/'); cout << first << endl; // debugging: it doesn't output 'sp'...so fin is not getting passed. Spinnerbait spinnerbaitLure; SpinnerbaitList spinList; spinnerbaitLure.inputSpinnerbait(fin); while (!fin.fail()) { spinList.insertSpinnerbait(spinnerbaitLure, 0); spinnerbaitLure.inputSpinnerbait(fin); } }
I don't understand why fin wouldn't be getting passed here. This seems simple enough. On a whim, I even tried changing that to istream &sin. No go. I'd appreciate ANY input. Thanks!
It should be istream&, but that not the problem.
I see you are using a string (the variable print), why don't you use a
string instead of an array for first? Te big advantage of strings is that
they automatically grow, you don't have to say how big they are, so you
can't make the mistake you've made with first. The other advantage is that
you can compare strings with ==, you don't have to use strcmp.
string first;
getline(first, '/');
if (first == "sp")
Very simple.
john
> string first; getline(first, '/');
getline(fin, first, '/');
if (first == "sp")
Sorry.
john
Francis Bell wrote: I just found that my fin stream is not getting passed to my readInASpinnerbait function. Here's what I have:
This is impossible (or so I would like to think...).
What do you mean by "doesn't get passed"?
string print; fin.get(first, 4, '/'); cout << first << endl; // debugging: it doesn't output // 'sp'...so fin is not getting passed.
I am suspicious about your logic. You read "sp" before sending fin to
the function. Then you expect to read it again?????
After read, the internal pointer is moved forward. Hence consecutive
calls to ifstream::read will not give you the same result, unless you
have a repeated string....
What I mean, unless your input is "spsp", and you call read with 2
instead of 4 as your argument, you shouldn't get back "sp" on
consecutive reads.
JLR
Jorge Rivera wrote: Francis Bell wrote:
I just found that my fin stream is not getting passed to my readInASpinnerbait function. Here's what I have:
This is impossible (or so I would like to think...). What do you mean by "doesn't get passed"?
> string print; > fin.get(first, 4, '/'); > cout << first << endl; // debugging: it doesn't output > // 'sp'...so fin is not getting passed.
I am suspicious about your logic. You read "sp" before sending fin to the function. Then you expect to read it again?????
After read, the internal pointer is moved forward. Hence consecutive calls to ifstream::read will not give you the same result, unless you have a repeated string....
What I mean, unless your input is "spsp", and you call read with 2 instead of 4 as your argument, you shouldn't get back "sp" on consecutive reads.
JLR
Thanks everyone for your input. I was doing it completely wrong. I was
treating like something like an integer or the like that can be passed
by value or reference. I've still got a problem with 'data flow'
somewhere that I haven't been able to trace, but I'm going to look at it
a little more before trying to post that here; it involves several
functions. Thanks all for your help!
Frank This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mahmood Ahmad |
last post by:
Hello,
I have written a program that reads three types of records, validates
them acording to certain requirements and writes the valid records
into a binary file. The invalid records are...
|
by: ragi |
last post by:
Short version of my program:
ifstream File;
File.open("test.txt");
if(!File.good()) return;
Func(File); <--cannot convert parametr 1 from 'std::ifstream' to
'std::istream'
|
by: Drewdog |
last post by:
I am getting some error messages which I can't figure out their
meaning. I have the code setup, I think it's correct but it doesn't
work. My goal is to get this program to read from a data file and...
|
by: SStory |
last post by:
Hi all,
I really needed to get the icons associated with each file that I want to
show in a listview.
I used the follow modified code sniplets found on the internet.
I have left in...
|
by: acheron05 |
last post by:
Hi there,
Hopefully I won't fit the stereotype of the typical student posting his
assignment to be written for him, but I am quite stuck. If anyone could
give me some help in how to create...
|
by: B. Williams |
last post by:
I have an assignment that requires me to write a program that uses a class, a constructor, a switch, and store the records in a text file. The second requirement is to create a function called...
|
by: NewYorker |
last post by:
Hello brothers and sisters,
Please help me complete this program and get the output shown below.
Here is all I have
___________________________________________________________
This...
|
by: priyajohal |
last post by:
#include<fstream.h>
#include<process.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<ctype.h>
#include<stdio.h>
void setup()
void help();
|
by: charmeda103 |
last post by:
i have this program that i am almost done with, i am one part away from being done.
the last part is putting the results together;
here is the results that i need to put in code. do u have any...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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...
| |