473,501 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

function should have a prototype

1 New Member
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 31044
Savage
1,764 Recognized Expert Top Contributor
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
keerthiramanarayan
13 New Member
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 New Member
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 New Member
Look at String mystr; That declaration should be string mystr; all letters in small letters.
Jan 2 '08 #5
keerthiramanarayan
13 New Member
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 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Contributor
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 Recognized Expert Top Contributor
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
bineet276
1 New Member
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
5959
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
2079
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
3017
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
105489
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
1372
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
2219
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
2530
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
6563
by: mahendra23 | last post by:
can anybody tell me pure virtual function in c++ have body present or not?
2
1285
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....
0
7164
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,...
0
7046
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...
0
7230
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,...
1
6936
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...
0
7424
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5522
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4958
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...
1
699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
330
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.