472,984 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

function should have a prototype

Hi all,

I am new to C++...I tried to compile the following program...

#include<iostream.h>
#include<conio.h>
#include<string>
#include<stdio.h>

int main() {
String mystr;
cout << "What is your name?";
getline(cin,mystr);
cout << "my name is:" << mystr;
cout << "What is your favourite team?";
getline(cin, mystr);
cout << "My favourite team is " << mystr;
getch();
return 0;
}

but i am getting the error 'function getline should have a prototype'...I am getting other errors as well apart from this ...but i think if i can add the relevant "#include..." i can fix this error..can anyone please tell me what is it for 'getline' function...thnk in advnce...
Dec 31 '07 #1
10 30888
Savage
1,764 Expert 1GB
Hi all,

I am new to C++...I tried to compile the following program...

#include<iostream.h>
#include<conio.h>
#include<string>
#include<stdio.h>

int main() {
String mystr;
cout << "What is your name?";
getline(cin,mystr);
cout << "my name is:" << mystr;
cout << "What is your favourite team?";
getline(cin, mystr);
cout << "My favourite team is " << mystr;
getch();
return 0;
}

but i am getting the error 'function getline should have a prototype'...I am getting other errors as well apart from this ...but i think if i can add the relevant "#include..." i can fix this error..can anyone please tell me what is it for 'getline' function...thnk in advnce...
It's namespace that you are missing.You can use std::getline or add this line after includes:

Expand|Select|Wrap|Line Numbers
  1. using namespace std;
PS:Please use [code=cpp] tags around your c++ code

Savage
Dec 31 '07 #2
Hi all,

I am new to C++...I tried to compile the following program...

#include<iostream.h>
#include<conio.h>
#include<string>
#include<stdio.h>

int main() {
String mystr;
cout << "What is your name?";
getline(cin,mystr);
cout << "my name is:" << mystr;
cout << "What is your favourite team?";
getline(cin, mystr);
cout << "My favourite team is " << mystr;
getch();
return 0;
}

but i am getting the error 'function getline should have a prototype'...I am getting other errors as well apart from this ...but i think if i can add the relevant "#include..." i can fix this error..can anyone please tell me what is it for 'getline' function...thnk in advnce...
I would like to add to the above reply. You should refrain from using the .h when including standard c++ libraries. So preferably use
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
instead of
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2.  
.

You have used the notation for string but have not done so in the case of iostream.
Jan 1 '08 #3
Andr3w
42
Well even if he didn't use the namespace he could easily do:

Expand|Select|Wrap|Line Numbers
  1. // instead of
  2. cout >> "something"
  3.  
  4. // he could write
  5. std::cout >> "something else"
  6.  
That's for all namespaces in C++, either you include them and you don't use the global operator if you want to use a function of a property that's in them or you use the using operator the namespace's name and add global operator and the function or property that's declared in it.

generally it's
Expand|Select|Wrap|Line Numbers
  1. using namespace namsepace_name;
  2.  
Becareful tho if you include namespaces that have functions with the same name ;)
Jan 1 '08 #4
manjuks
72
Look at String mystr; That declaration should be string mystr; all letters in small letters.
Jan 2 '08 #5
I repaired the code to this and it works fine. (on VC and gcc atleast). This avoids the name clash problem as pointed out above. The
Expand|Select|Wrap|Line Numbers
  1. using std::cout;
  2.  
also makes sure that you don't go around typing std:: each time you use the function/class

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::string;
  5. using std::cin;
  6. using std::cout;
  7.  
  8. int main() {
  9.     string mystr;
  10.     cout << "What is your name?";
  11.     getline(cin,mystr);
  12.     cout << "my name is:" << mystr;
  13.     cout << "What is your favourite team?";
  14.     getline(cin, mystr);
  15.     cout << "My favourite team is " << mystr;
  16.     return 0;
  17. }
  18.  
Regards,
Keerthi Ramanarayan
Jan 2 '08 #6
manjuks
72
I repaired the code to this and it works fine. (on VC and gcc atleast). This avoids the name clash problem as pointed out above. The
Expand|Select|Wrap|Line Numbers
  1. using std::cout;
  2.  
also makes sure that you don't go around typing std:: each time you use the function/class

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::string;
  5. using std::cin;
  6. using std::cout;
  7.  
  8. int main() {
  9.     string mystr;
  10.     cout << "What is your name?";
  11.     getline(cin,mystr);
  12.     cout << "my name is:" << mystr;
  13.     cout << "What is your favourite team?";
  14.     getline(cin, mystr);
  15.     cout << "My favourite team is " << mystr;
  16.     return 0;
  17. }
  18.  
Regards,
Keerthi Ramanarayan
Hi keerthi,

why you have used
(code : cpp)
using std::string;
using std::cin;
using std::cout;

Instead you can use
(code : cpp)
using namespace std;
Jan 2 '08 #7
Savage
1,764 Expert 1GB
Hi keerthi,

why you have used
(code : cpp)
using std::string;
using std::cin;
using std::cout;

Instead you can use
(code : cpp)
using namespace std;
No need to use whole namespace,when you can use just parts of it.This makes *.obj and .exe files smaller.

Savage
Jan 2 '08 #8
oler1s
671 Expert 512MB
No need to use whole namespace,when you can use just parts of it.This makes *.obj and .exe files smaller.
Uhh...what? I'm going to assume this was said in a muddled state of mind, as this is most certainly a wrong thing to say.
Jan 2 '08 #9
Savage
1,764 Expert 1GB
Uhh...what? I'm going to assume this was said in a muddled state of mind, as this is most certainly a wrong thing to say.
Ooops..........sorry for that.

OP,when said using std::cout(e.g) you can now just use cout without std prefix,while others you must still prefix with std.

Only two good reasons for doing this is evading possible name conflicts.What if there is (for e.g) variable x inside std(there is no variable x inside std just a example) and you put :

using namespace std;

and declare a variable(or function) called x,there will be name conflict.But with using just some things from the namespace you can possible avoid these conflicts.
Jan 2 '08 #10
U can use the following code and execute . U would not get any error while compiling and executing the code. So proceed:-

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

int main()
{
clrscr();
char mystr[50];
cout<< "What is your name?\n";
gets(mystr);
cout<<"my name is:"<<mystr<<"\n";
cout<<"What is your favourite team?\n";
gets(mystr);
cout<<"My favourite team is"<<mystr<<"\n";
getch();
return 0;
}
Feb 21 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Ian | last post by:
The title says it all. I can see the case where a function is to be called directly from C, the name mangling will stuff this up. But I can't see a reason why a template function can't be...
5
by: Alfonso Morra | last post by:
Hi all, I came accross this FP signature and it has me baffled. Can anyone explain this signature to me - i.e what are the input and output types ? void(*(*foo)(int))(int,void(*)(int)) ...
3
by: steven.ke | last post by:
Hi all, I am trying to use the sortBy function in the prototype.js library. Nevertheless, I can't work out what to include in the iterator function. Can someone shed some light on this? Thanks in...
13
by: richasaraf | last post by:
Hi guys, Can someone help me... I want to know... can we have OUT, IN OUT parameters in function? :confused: And can we use it in select statement ? Thanks a lot ! Take Care Richa :)
4
by: ygao | last post by:
>>compile('U"ÖĞ"','c:/test','single') <code object ? at 00F06B60, file "c:/test", line 1> <code object ? at 00F06BA0, file "c:/test", line 1> u'\xd6\xd0' u'\u4e2d' why is the result different?...
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
5
by: cyborg81 | last post by:
SOMEONE PLS HELP! im writing this code of a function prototype as follows: #include<iostream> #include<iomanip> using std::cin; using std::cout;
4
by: mahendra23 | last post by:
can anybody tell me pure virtual function in c++ have body present or not?
2
LeoTD
by: LeoTD | last post by:
Dear all, I have a problem: I want to execute some codes in page1 and return result in page2. In ASP, the Server.Transfer function is OK. But in PHP, i don't know have function could do it or not....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.