LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-09-2005, 12:32 PM   #1
azucarmom
LQ Newbie
 
Registered: Dec 2004
Posts: 16

Rep: Reputation: 0
Unhappy HELP!! no match for `_IO_ostream_withassign & >> char[36


I'm trying to write a very basic, quick little program for my C++ class and I'm running into error after error. Seems like I fix one, and another occurs. I'm not even into the meat of the program yet! ah!
Anyway, here is the code:


//P3

#include <string>
#include "files.h"

using namespace std;

int main(void)
{

const int ROW_MAX = 15;
const int COL_MAX = 2;

ifstream fin;
ofstream fout;

int r;
int c;

string ListArray[ROW_MAX][COL_MAX];

ListArray list;

GetInputFile(fin);

while (!fin) //Read the input file
{
for (r=0; r<ROW_MAX; r++)
{
for (c=0; c<COL_MAX; c++)
{
fin >> list[r][c];
}
}
}

// test to check string input
for (r=0; r<ROW_MAX; r++)
{
for (c=0; c<COL_MAX; c++)
{
cout << list[r][c];
}
}
return 0;
}

And here is the contents of files.h, supplied by my professor:
// files.h


#ifndef _FILES
#define _FILES

#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>

using namespace std;

void GetInputFile(/* out */ ifstream& inFile);
// Sets up an input file stream
// Pre: None
// Post: inFile parameter has been opened to the input file specified by the user



void GetOutputFile(/* out */ ofstream& outFile);
// Sets up an output file stream
// Pre: None
// Post: outFile parameter has been opened to the output file specified by the user

#endif

I get the following error when attempting to compile and link:

131p3.cpp: In function `int main()':
131p3.cpp:39: no match for `_IO_ostream_withassign & >> char[36]'

Can someone please tell me what I'm doing wrong? I'm sure it's something insanely obvious and stupid, and I'm so fried I can't figure it out. Spring break my butt!
Thanks!
 
Old 03-09-2005, 01:32 PM   #2
beforemath
LQ Newbie
 
Registered: Feb 2005
Posts: 8

Rep: Reputation: 0
Just a small question:

Why exactly are you declaring
Code:
string ListArray[Row_Max][Col_Max];

ListArray list;
.
.
.
cout << list[r][c];
instead of using
Code:
string ListArray[Row_Max][Col_Max];
.
.
.
cout << ListArray[r][c];
I'm kind of unclear what the "ListArray list" declaration is for.

Does the code work if you take that out and replace the instances of "list" with "ListArray"?

~bm
 
Old 03-09-2005, 01:40 PM   #3
azucarmom
LQ Newbie
 
Registered: Dec 2004
Posts: 16

Original Poster
Rep: Reputation: 0
Oops, that should actually be a typedef:


typedef string ListArray[Row_Max][Col_Max];

ListArray list;


And that doesn't fix it, I just get a new error:

/tmp/ccu9baEd.o: In function `main':
/tmp/ccu9baEd.o(.text+0xfc): undefined reference to `GetInputFile(ifstream &)'
collect2: ld returned 1 exit status

Not sure what those mean, any ideas?
Thanks!
 
Old 03-09-2005, 03:37 PM   #4
azucarmom
LQ Newbie
 
Registered: Dec 2004
Posts: 16

Original Poster
Rep: Reputation: 0
I did figure it out, to make a long story short, I wasn't linking some files correctly and that's what that error was regarding.

Anyway, I've gotten a bit further and I'm trying to compare the name a user types in to the name in my array. Here's the code segment:******************************


cout << "Please enter your name exactly as it appears on the shareholder list." << endl;
cout << "Or, you may type Q to quit." << endl;

cin >> fname;
if ((fname[0]="q")&&(fname[1]=" ")&&(fname[2]=" "))
{
return 0;
}
cin >> lname;
cin.ignore(256, '\n');

for (r=0; r<ROW_MAX; r++)
{
if ( strcmp( fname, list[r]) == 0 )
{

for (c=0; c<COL_MAX; c++)
{ if ( strcmp( lname, list[c]) == 0 )
cout << fname << " " << lname << " may attend";
else
cout << fname << " " << lname << " may NOT attend";
}
}
else
cout << fname << " " << lname << " may NOT attend";
}
**********************************************************************
Now, when I attempt to compile, I get:


131p3.cpp: In function `int main()':
131p3.cpp:54: warning: assignment to `char' from `char *' lacks a cast
131p3.cpp:54: warning: assignment to `char' from `char *' lacks a cast
131p3.cpp:54: warning: assignment to `char' from `char *' lacks a cast
131p3.cpp:65: cannot convert `fname' from type `string' to type `const char *'
131p3.cpp:69: cannot convert `lname' from type `string' to type `const char *'

<sigh> Seems yet again, I've done something wrong - looks to be in my comparision of the strings. How can I fix this?

Thanks everyone!
 
Old 03-09-2005, 05:03 PM   #5
beforemath
LQ Newbie
 
Registered: Feb 2005
Posts: 8

Rep: Reputation: 0
What is the declaration of fname and lname?

are they:
Code:
string lname[SIZE];
or
Code:
string lname;
If you declared it as the latter, you can't compare
Code:
lname[x] == " "; // you are comparing a char (in theory) with a string

lname[x] == ' '; // you are now comparing char with char
                         // and use == instead of =
                         // you are trying to compare, not trying to assign
and later...
you can't assign fname (a string I'm assuming) to a pointer to a string.
You should probably assign fname = list[x][y] or something.

That looks like what the problem is to me.
hope it helps or sets you in the right direction.


~bm
 
Old 03-09-2005, 05:29 PM   #6
azucarmom
LQ Newbie
 
Registered: Dec 2004
Posts: 16

Original Poster
Rep: Reputation: 0
they're
string fname, lname;

I need the user to enter his name, which I need to store
(currently cin >> fname>>lname

then, I need to search an array and see if that name is in the array. THe array is 2 columns, 15 rows.
The first column is the first name, the second column is the last.

How do I compare them? Do I have to go char by char in the strings (ugh)?

Thanks!
 
Old 03-10-2005, 08:42 AM   #7
beforemath
LQ Newbie
 
Registered: Feb 2005
Posts: 8

Rep: Reputation: 0
Nah, you don't have to go char by char.

Some versions of C compiler overload the == operator so you can compare
Code:
if (string1 == string2)
     { 
     do code
     }
but the standard is (or was) that the C compiler doesn't support this operation. Instead (since I see that you have string.h declared up there), you can use strcmp().
Code:
int x;
x = strcmp(string1, string2);
if (x < 0)
     string1 is 'less than' string2
if (x == 0)
     string1 is 'equal to' string2
if (x > 0)
     string1 is 'greater than' string2
remember that your 'list ' variable is a two-dimensional array of strings, so list[r] compared with fname won't work.

list[r][c] compared with fname will work, though.

Let me know if this helps.

~bm
 
Old 03-10-2005, 11:47 AM   #8
azucarmom
LQ Newbie
 
Registered: Dec 2004
Posts: 16

Original Poster
Rep: Reputation: 0
I got it to work using:
Code:
bool canAttend = false;
for (r=0; r<ROW_MAX; r++)
{
    if (fname == list[r][0] && lname == list[r][1])
   {
     canAttend = true;
     break;
   }
}

if (canAttend)
  cout << fname << " " << lname << " may attend";
else
  cout << fname << " " << lname << " may NOTattend";

I tried strcmp but it didn't work.
I don't know why I was trying to reference list as a one dimensional array! Total brain fart I think.
Thanks for your help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep [A-Z] & [a-z] match both upper and lower case. jschiwal Linux - General 4 05-28-2005 06:43 AM
Assign a command to 'Alt Gr' itself and '&#711;' char in UT/Q3A kilgor Linux - Games 0 03-08-2005 03:50 PM
C Problem---convert char to char* totti10 Programming 11 11-06-2004 11:32 AM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM
LimeWireLinux & RedHat 7.2 Linux.....match? therion12 Linux - Networking 6 12-30-2001 07:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration