473,729 Members | 2,142 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<iostre am.h>
#include<conio. h>
#include<string >
#include<stdio. h>

int main() {
String mystr;
cout << "What is your name?";
getline(cin,mys tr);
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 31094
Savage
1,764 Recognized Expert Top Contributor
Hi all,

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

#include<iostre am.h>
#include<conio. h>
#include<string >
#include<stdio. h>

int main() {
String mystr;
cout << "What is your name?";
getline(cin,mys tr);
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<iostre am.h>
#include<conio. h>
#include<string >
#include<stdio. h>

int main() {
String mystr;
cout << "What is your name?";
getline(cin,mys tr);
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

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

Similar topics

22
6018
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 given extern "C" linkage where it is to be assigned to a C function pointer. Ian
5
2091
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)) Thanks
3
3026
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 advance.
13
105807
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
1386
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? a bug or another reason?
5
2242
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
2537
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
6636
by: mahendra23 | last post by:
can anybody tell me pure virtual function in c++ have body present or not?
2
1294
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. Please help me!! Thanks a lot :D
0
8913
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
9280
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
9200
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,...
0
9142
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2162
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.