2

I'm just learning some stuff about cryptography and I made a cool program to encrypt any message by rotating the letters through the alphabet a given number of letters...anyway...I have it all set up but I can't give it multiple words to encrypt because it ends the input after one word...(using cin)...how would I get cin to not stop taking input until I hit return?

JacKeown
  • 2,180
  • 5
  • 24
  • 30
  • [This SO answer](http://stackoverflow.com/questions/2912520/read-file-contents-into-a-string-in-c/2912614#2912614) might be useful to you. – academicRobot Apr 05 '11 at 03:20

3 Answers3

3

How about std::getline()?

http://www.cplusplus.com/reference/iostream/istream/getline.html

Example:

#include <iostream>
#include <string>
using namespace std;

string line;
getline( std::cin, line );
TiansHUo
  • 8,049
  • 6
  • 42
  • 57
2

You want to use getline to read a full line.

Michael Aaron Safyan
  • 87,518
  • 14
  • 130
  • 194
2

Use cin.getline() to read a line? (Or, probably better, as Martin notes in a comment, use std::getline.)

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185