开发者

C++ spaces mark end of input in cin?

开发者 https://www.devze.com 2023-02-22 15:51 出处:网络
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

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 i开发者_JAVA技巧t ends the input after one word...(using cin)...how would I get cin to not stop taking input until I hit return?


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 );


You want to use getline to read a full line.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号