A lot of beginners make this mistake. Once you're entered your name you need to have your program establish a HTTP connection with switchboard.com using their CGI script with your name as its parameters. Save the HTTP response to a string, parse the string for your address and then output that to the screen using cout. That's a lot simpler than just telling your program what your address is yourself.
Any help we can give you with Assignment #2 be sure to let us know. :)
int main (void)
{
cout << "Hello, World! I'm completely operational and all my circuits are
functioning perfectly! :)\nAnd you are?..." ;
string s ;
cin >> s ;
cout << "Good " << (military::time() < 12 ? "morning" : "afternoon")
<< ", " << s << "! Where do you live? " ;
string t ;
cin >> t ;
cout << "You live at " << t << ", " << s << "?\nI'll pick you up at 7, then."
return 0 ;
}
I guess I figured that anyone who knew their own address would have figured that out for themselves by now. :)
As the title of the topic suggest is better using getline than cin >>, I don't think can exist an address made of a single word.
The site you gave provides only addresses on the US and if there are more people with the same name how would the program be able to find out which is the right address?
I can't say I disagree that using the string class is better than using character arrays, although I do think that everyone should be able to do things either way.
#including a file does, however, prepend that file's contents to the contents of yours when it gets preprocessed, which means that your file increases in size by the size of any included file as it is preprocessed, not just by one line.
Thanks all of my dear fellows whome try their level best to help me.
This is the same programme which i made myself.
Now see this clearly and then give the answer of my one Question.
#include<iostream>
#include<string>
using namespace std;
int main()
{
char name[30];
string address;
cout<<"Enter your complete name: ";
cin.getline (name,30);
cout<<"Enter your complete address: ";
getline (cin,address);
This is exactly right and fulfils my requirement but if i take both the variable as a string then it does not give any error but while exicuting this will not fulfill my requirments. Whats the reason of this ?
Showing us the code that works doesn't help us figure out what's wrong with the code that doesn't work now, does it? Maybe if you paste in the code that doesn't work we'll be able to tell you what's wrong with it.
See what you did, Bazzy? I had this all straightened out with character arrays and then you just had to go and bring strings into it. Now it's hopeless.