F
Francis Bell
Hello,
I've got a program that is reading in a data file of 25 lines. Here is
an example of the first two lines:
sp/spinnerbait/AAA Lures/Mad Phil/silver/bass/1/1
f/floating minnow/AAA Lures/Skinny Minney/green/bass/0/0/0
In my program, I need to read in each line, BUT, I need to build a
different object based upon the characters in the first field. So, I
need to GET the first characters. And here's where I'm doing something
incorrectly. This is what I've got so far:
char readInFirstChars(ifstream &fin) {
char *first;
fin.get(first, 3, '/');
cout << first; // debugging line to see what is output
}
return first;
}
The above code give me a compile error stating:
" invalid conversion from `char*' to `char'"
I tried the get function with the single character parameter like such:
char first;
fin.get(first);
cout << first << endl;
return first;
and it works fine. So I must be doing something wrong with the pointer.
The other tangent problem I'm having with this how to properly cycle
through the input file so it only reads in the first field and then
moves on to the next line. I tried
while (fin.good()) {
char first;
fin.get(first);
cout << first << endl;
}
return first;
Which looped, but it output the entire file. I only need the first
field. If the first field were only one character, then the only
problem I would be dealing with is the loop problem, but since it's
either 1 or 2 characters (with the end delimeter being '/'), I'm also
dealing with the get() problem.
Thanks for any advice.
Frank
I've got a program that is reading in a data file of 25 lines. Here is
an example of the first two lines:
sp/spinnerbait/AAA Lures/Mad Phil/silver/bass/1/1
f/floating minnow/AAA Lures/Skinny Minney/green/bass/0/0/0
In my program, I need to read in each line, BUT, I need to build a
different object based upon the characters in the first field. So, I
need to GET the first characters. And here's where I'm doing something
incorrectly. This is what I've got so far:
char readInFirstChars(ifstream &fin) {
char *first;
fin.get(first, 3, '/');
cout << first; // debugging line to see what is output
}
return first;
}
The above code give me a compile error stating:
" invalid conversion from `char*' to `char'"
I tried the get function with the single character parameter like such:
char first;
fin.get(first);
cout << first << endl;
return first;
and it works fine. So I must be doing something wrong with the pointer.
The other tangent problem I'm having with this how to properly cycle
through the input file so it only reads in the first field and then
moves on to the next line. I tried
while (fin.good()) {
char first;
fin.get(first);
cout << first << endl;
}
return first;
Which looped, but it output the entire file. I only need the first
field. If the first field were only one character, then the only
problem I would be dealing with is the loop problem, but since it's
either 1 or 2 characters (with the end delimeter being '/'), I'm also
dealing with the get() problem.
Thanks for any advice.
Frank