473,698 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot convert from char[20][40] to char*

This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_ist ream<_Elem,_Tra its>::_Myt
&std::basic_ist ream<_Elem,_Tra its>::getline(_ Elem *,std::streamsi ze)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipit y Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(boo kTitle, 40); //****this is the line it doesnt
like*****//
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipit y Booksellers\n\n ";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\ tTitle\t\t\t\tP rice\t\tTotal\n ";

cout<<"________ _______________ _______________ _______________ _______________ ____________\n" ;
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n \n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}

Nov 22 '05 #1
7 5331
"GRoll35" <mi**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_ist ream<_Elem,_Tra its>::_Myt
&std::basic_ist ream<_Elem,_Tra its>::getline(_ Elem *,std::streamsi ze)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipit y Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(boo kTitle, 40); //****this is the line it doesnt
like*****//
Pick an element. cin.getline(boo kTitle[index], 40); is probably what you
meant.
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipit y Booksellers\n\n ";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\ tTitle\t\t\t\tP rice\t\tTotal\n ";

cout<<"________ _______________ _______________ _______________ _______________ ____________\n" ;
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n \n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}

Nov 22 '05 #2

"Jim Langston" <ta*******@rock etmail.com> wrote in message
news:KP******** *******@fe02.lg a...
"GRoll35" <mi**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_ist ream<_Elem,_Tra its>::_Myt
&std::basic_ist ream<_Elem,_Tra its>::getline(_ Elem *,std::streamsi ze)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipit y Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(boo kTitle, 40); //****this is the line it doesnt
like*****//
Pick an element. cin.getline(boo kTitle[index], 40); is probably what you
meant.


er, I think it has to be cin.getline(&bo okTitle[index], 40);
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipit y Booksellers\n\n ";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\ tTitle\t\t\t\tP rice\t\tTotal\n ";

cout<<"________ _______________ _______________ _______________ _______________ ____________\n" ;
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n \n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}


Nov 22 '05 #3
thanks Jim. That fixed that error now I get all these.. I'm guessing
they are all connected to the same thing..

ser6 fatal error LNK1120: 2 unresolved externals
ser6 error LNK2001: unresolved external symbol "char (* dateAdded)[10]"
(?dateAdded@@3P AY09DA)
ser6 error LNK2001: unresolved external symbol "char (* dateAdded)[10]"
(?dateAdded@@3P AY09DA)
ser6 error LNK2001: unresolved external symbol "char (* bookTitle)[40]"
(?bookTitle@@3P AY0CI@DA)
ser6 error LNK2001: unresolved external symbol "char (* bookTitle)[40]"
(?bookTitle@@3P AY0CI@DA)

im playing around with it to see what it could be.. any idea?

Nov 22 '05 #4
GRoll35 wrote:
This is 1 source page of a project im working on. i just have this one
error. i'll show the error then show the code.. i'll point out the line
that it doesn't like. if anyone has any ideas or advise that would be
great. thank you very much!

(42): error C2664: 'std::basic_ist ream<_Elem,_Tra its>::_Myt
&std::basic_ist ream<_Elem,_Tra its>::getline(_ Elem *,std::streamsi ze)' :
cannot convert parameter 1 from 'char [20][40]' to 'char *'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
--Code--
//cashier

#include <iostream>
#include <iomanip>
#include "cashier.h"

using namespace std;

int cashier()
{
//declare variables
// char date[10];
int quant = 0;
// char isbn[15];
// char title[40];
// float price = 0;
float tax = .06f;
char yesNo;
Don't declare variables until you need them, and then declare them in
as small a scope as possible. You never use "quant", and "tax" should
be const.

extern char isbn[20][14];
extern char bookTitle[20][40];
extern char dateAdded[20][10];
extern int qtyOnHand[20];
extern float retail[20];
Global variables?! Try passing parameters to your function instead.


do
{
for(int index =0; index < 20; index++)
{
system("cls");
cout << "Serendipit y Booksellers\n";
cout << " Cashier Module\n\n";
cout << "Date: ";
cin >> dateAdded[index];
cout <<"\n" <<"Quantity of Book: ";
cin >> qtyOnHand[index];
cout << "\n" << "ISBN: ";
cin >> isbn[index];
cin.ignore();
cout << "\n" << "Title: ";
cin.getline(boo kTitle, 40); //****this is the line it doesnt
like*****//
Try:

cin.getline( bookTitle[index], 40 );
cout <<"\n" << "Price: ";
cin >> retail[index];
system("cls");

float total = qtyOnHand[index] * retail[index];
float ttax = tax*total;
float ftotal = ttax+total;

//final output
cout << "Serendipit y Booksellers\n\n ";
cout << "Date: " << dateAdded[index] << "\n\n\n";

cout <<"Qty\tISBN\t\ tTitle\t\t\t\tP rice\t\tTotal\n ";

cout<<"________ _______________ _______________ _______________ _______________ ____________\n" ;
cout << qtyOnHand[index];
cout << "\t";
cout << isbn[index];
cout << "\t";
cout << bookTitle[index];
cout << "\t\t";
cout<< setprecision(2) << fixed;
cout << "$ " << retail[index];
cout << "\t\t";
cout << "$ " << total;
cout << "\n\n\n";
cout<<" \t \t\tSubtotal " << setw(41) << "$ " << total
<<"\n";
cout<<" \t \t\tTax " << setw(47)<< "$ " << ttax <<"\n";
cout<<" \t \t\tTotal " << setw(44) << "$ " << ftotal
<<"\n";
cout<<"\nThank You for Shopping at Sereendipity!\n \n";

cout <<"\n\tWould you like to make another purchase? (Y/N) ";
cin >> yesNo;
}
} while(yesNo == 'Y');


cout << "\n\n";
return 0;
}


Cheers! --M

Nov 22 '05 #5
Jim Langston <ta*******@rock etmail.com> wrote:
"Jim Langston" <ta*******@rock etmail.com> wrote in message

"GRoll35" <mi**********@g mail.com> wrote in message
extern char bookTitle[20][40]; cin.getline(boo kTitle, 40); //****this is the line it doesnt
like*****//


Pick an element. cin.getline(boo kTitle[index], 40); is probably
what you meant.


er, I think it has to be cin.getline(&bo okTitle[index], 40);


Well, if bookTitle[index] really does not work (tho I think it
should), then &bookTitle[index][0] would be correct for sure.

regards
--
jb

(reply address in rot13, unscramble first)
Nov 22 '05 #6
i added the & like you said Jim.. that fixes all them errors now I'm
left with just this one..

(42): error C2664: 'std::basic_ist ream<_Elem,_Tra its>::_Myt
&std::basic_ist ream<_Elem,_Tra its>::getline(_ Elem *,std::streamsi ze)' :
cannot convert parameter 1 from 'char (*__w64 )[40]' to 'char *'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]

Nov 22 '05 #7
GRoll35 wrote:
i added the & like you said Jim.. that fixes all them errors now I'm
left with just this one..

(42): error C2664: 'std::basic_ist ream<_Elem,_Tra its>::_Myt
&std::basic_ist ream<_Elem,_Tra its>::getline(_ Elem *,std::streamsi ze)' :
cannot convert parameter 1 from 'char (*__w64 )[40]' to 'char *'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]


Quote the code you have now. I'm guessing that you have

int cashier(char bookTitle[20][40])
{
....
cin.getline(boo kTitle, 40);

but of course I could be wrong.

To solve this yourself remember that bookTitle is an array of titles, so
to input a title you have to say which title in the array of titles
you are trying to input, i.e.

cin.getline(boo kTitle[index], 40);

or something.

john
Nov 22 '05 #8

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

Similar topics

2
1585
by: Stijn Goris | last post by:
hi all, I have a site where a user can enter text (newspost). I recently discovered that when %20 is entered the text is properly inserted in the database (INSERT) but isn't shown on the page isn't shown on the page (SELECT). The text is shown via printf(nl2br(stripslashes($myrow))); where myrow is the text containing the %20 . Someone knows whats goin on? Regards
2
36254
by: Ralph Smith | last post by:
I'm having trouble copying a database to another machine. Here are the two table's in ths database and the sql commands: DROP TABLE IF EXISTS `clients`; CREATE TABLE `clients` ( `client_id` int(10) unsigned NOT NULL auto_increment, `lastname` char(15) NOT NULL default '', `firstname` char(15) NOT NULL default '', `birthdate` date NOT NULL default '0000-00-00',
17
67683
by: Magix | last post by:
Hi, How do I set the char to empty ? let say I have, char test; can I do like this : *test = NULL;
7
66682
by: MilanB | last post by:
Hello How to convert char to int? Thanks
6
109358
by: Rick | last post by:
Hi guys, i've seen it in VC++ but in C# how do i conver string to char?? in c++ is like http://support.microsoft.com/?kbid=311259 Regards
1
1300
by: Elhanan | last post by:
hi.. sorry for the cross posting, i'm simply not sure where this goes (i'm still genrating this from an asp page). i'm trying to printout normal text from IE using Generic Text Driver like so:
5
5040
by: wong_powah | last post by:
#include <vector> #include <iostream> using std::cout; using std::vector; enum {DATASIZE = 20}; typedef unsigned char data_t;
5
17268
by: oliver.andrich | last post by:
Hi, can anybody with ctypes experience tell me, how to handle a C function that returns an unsigned char*? Obviously it is not a restype of c_char_p. Best regards, Oliver
14
13505
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h>
0
8673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.