Sign in to follow this  

stringstream question

This topic is 3862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i started learning about string stream and i was trying to make something to better understand/get used to it. i keep getting errors though what am i doing wrong?
#include <iostream>
#include <string>
using namespace std;

int main()
{
   string adress;
   int whereulive;
   
   cout<<"What is your full adress?\n";
   getline (cin, adress);
   stringstream(adress) >> whereulive;
   cout<<"I know where you live.\n";
   cin.get();
   cout<< whereulive;
      }

Share this post


Link to post
Share on other sites
Quote:
Original post by HeyHoHey
i keep getting errors though what am i doing wrong?

You are making errors.

If you want to know how to fix the errors, you could start by telling us what the errors are. (And in general, it also never hurts to explain what you're trying to do)

Always make it easy for people to answer your questions.

Share this post


Link to post
Share on other sites
Your example doesn't make much since...

Look at this...

std::string streetname = "Oak St.";
int addressnumber = 1500;

std::stringstream fullAddress;
fullAddress << addressnumber << " " << streetname;

std::cout << "You live at: " << fullAddress.str() << std::endl;



This would output "You live at: 1500 Oak St.".

Share this post


Link to post
Share on other sites

This topic is 3862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this