cin problems

I am trying to make a console application which takes you name, and a message and prints it to a .txt file with the time and date. However, if the person enters a name that has more than one word in it, it skips the next question, and when it prints to the .txt file it only prints on word.

This is the app code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// logs.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <locale>
using namespace std;


string name;
string input;

int main()
{

	cout << "This program will enter a timestapmed event into the logs with your name.\n\n\n" << endl;
	time_t curr=time(0);
	ofstream myfile;
	cout << "Please enter your name: ";
	cin >> name;
	cout << "Please enter your log input: ";
	cin >> input;
	myfile.open ("logs.txt", ios::app);
	myfile << "\n\n---------------------------------------------------------------------" << endl;
	myfile << "\n" << ctime(&curr) << endl;
	myfile << "\n Name: " << name << endl;
	myfile << "\n Log: " << input << endl;
	myfile.close();


	return 0;
}


See what I mean by skipping the next question when 2 words are entered?
http://screensnapr.com/e/go9GNa.png

And it prints to the Log like this:
http://screensnapr.com/e/dROE4U.png


Also:
Would it be possible to make it create/save to a .txt file in another directory?
1
2
cout << "Please enter your name: ";
getline(cin, name);//input the entire line 


1
2
cout << "Please enter your log input: ";
getline(cin, input);
std::cin takes input until the first white space. The fellow above me is right, you want to use getline(cin, variable) if you want to get multiple words. But, the default delimiter character of this is the new line character, so keep that in mind.
Topic archived. No new replies allowed.