cin on a multiword string only returns one word

I'm trying to create a basic note saving program, but whenever I try to get an input it only takes the first word. Here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string note;
  ofstream myfile;
  myfile.open ("note.txt");
  cin >> note;
 
  myfile << note;
  
  myfile.close();
  return 0;
}


Is there any way to get it to make the note variable multiple words?
std::getline(std::cin, note);
Try getline(cin, note); instead.
Thanks guys!
closed account (4GEURXSz)
you shall use getline(cin, note); rather than cin >> note;
Last edited on
Topic archived. No new replies allowed.