Really easy question about input commands

What is the difference between CIN / and GetLine ?

Page 1 of 1

5 Replies - 592 Views - Last Post: 26 September 2009 - 06:03 PM Rate Topic: -----

#1 crackisgood4u  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 11-February 09

Really easy question about input commands

Post icon  Posted 26 September 2009 - 03:05 PM

I need to know the difference between a cout and a get line, please if you could explain it to me in detail I would appreciate it, I can't complete my assignment without a thorough understanding.
Is This A Good Question/Topic? 0
  • +

Replies To: Really easy question about input commands

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1074
  • View blog
  • Posts: 4,533
  • Joined: 09-June 09

Re: Really easy question about input commands

Posted 26 September 2009 - 03:20 PM

cin will only take input without null character ( a space)

with get line you can input into a hole line into a string like ( "Crack is good for you");

cin will only grab the first word
Was This Post Helpful? 0
  • +
  • -

#3 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: Really easy question about input commands

Posted 26 September 2009 - 03:29 PM

View Postcrackisgood4u, on 26 Sep, 2009 - 02:05 PM, said:

I need to know the difference between a cout and a get line

wOOT?
One is for output the other one for imput :(

just joking :)

Well as imaSexy said cin will only get the first part of the string untill it finds a space.
And getline will hold the entire string.

This post has been edited by poncho4all: 26 September 2009 - 03:30 PM

Was This Post Helpful? 0
  • +
  • -

#4 rekijitsu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 12-February 09

Re: Really easy question about input commands

Posted 26 September 2009 - 05:41 PM

View Postponcho4all, on 26 Sep, 2009 - 02:29 PM, said:

View Postcrackisgood4u, on 26 Sep, 2009 - 02:05 PM, said:

I need to know the difference between a cout and a get line

wOOT?
One is for output the other one for imput :(

just joking :)

Well as imaSexy said cin will only get the first part of the string untill it finds a space.
And getline will hold the entire string.



Yep, he would be right, I too can confirm the usefulness of getline :)

However I believe he said it ignores null values as if null is equal to spaces. Is it appropriate to use such wording?

The way I understood it getline retrieves spaces, but null values? What is the difference between spaces and the absence of data?

Also, if you need it, I googled online and this seemed like a good example of getline, if you need to know the syntax since it is different from typical cin >> or infile >>:

// istream getline
#include <iostream>
using namespace std;

int main () {
  char name[256], title[256];

  cout << "Enter your name: ";
  cin.getline (name,256);

  cout << "Enter your favourite movie: ";
  cin.getline (title,256);

  cout << name << "'s favourite movie is " << title;

  return 0;
}


This post has been edited by rekijitsu: 26 September 2009 - 05:44 PM

Was This Post Helpful? 0
  • +
  • -

#5 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

Re: Really easy question about input commands

Posted 26 September 2009 - 05:59 PM

Well spaces are data the represent ' ' but is not an integer and when receiving a string with cin, which is not apropiate it marks an end.
Was This Post Helpful? 0
  • +
  • -

#6 rekijitsu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 12-February 09

Re: Really easy question about input commands

Posted 26 September 2009 - 06:03 PM

View Postponcho4all, on 26 Sep, 2009 - 04:59 PM, said:

Well spaces are data the represent ' ' but is not an integer and when receiving a string with cin, which is not apropiate it marks an end.


Yep, I think that's a good way of thinking about it. when I hear null it always triggers something in my head that it isn't just a blank space, it's something more abstract :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1