Help with fstream and iostream

Hey im trying to creat a login
classical Username Passwort
So my problem is that when I enter Username exampel User Name it will take User as Username and Name as Passwort.

How do I let it accept the whitespace and wait until the User presses enter

tried with .getline, it work for me about the problem with the whitespace, but now it takes enter as nextline and not as accept input as set to Username or Passwort

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <fstream>
#include <iostream>
#include <string>
#include <sstream>

    using namespace std;

        string Username = "User name: ";
        string Passwort = "Pass wort: ";

        string False_Username = "Incorrect User name\n";
        string False_Passwort = "Incorrect Pass wort\n";

        string True_Username = "Valid User name\n";
        string True_Passwort = "Valid Pass wort\n";

        string Enter_Username = "Enter Your desired User name\n";
        string Enter_Passwort = "Enter Your desired Pass wort\n";

        string User_input;
        string User_input_1;

        string User_input_succed = "Your User name and Pass wort has been set!";

        string Exit = "Yes";
        string Test;

        string Question = "Enter Yes if you want to Exit";


    int main() //Start Main Function
        {


            ofstream User; //open ofstring

                User.open ("Testing.dat"); //open file to write

                        cout << Enter_Username; //open string to write into database
                            cin >> User_input;  //Detect user input
                        User<< "Username: " << User_input << endl; //print string and write input in file

                          cout << Enter_Passwort; //open string to write into database
                            cin >> User_input_1; //Detect user input
                        User << "Passwort: " << User_input_1;//print string and write input in file

            cout << endl << User_input_succed << endl; //print string
                 User.close();  //close file

            do      //start Exit command

            {
                cout << Question << '\n'; //print string
                  cin >> Test;  //Wait for User input

            }
            while (Exit != Test); //compare user input with Exit if not equal continue if equal exit program
        }

Using getline works for me.
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

string Username = "User name: ";
string Passwort = "Pass wort: ";

string False_Username = "Incorrect User name\n";
string False_Passwort = "Incorrect Pass wort\n";

string True_Username = "Valid User name\n";
string True_Passwort = "Valid Pass wort\n";

string Enter_Username = "Enter Your desired User name\n";
string Enter_Passwort = "Enter Your desired Pass wort\n";

string User_input;
string User_input_1;

string User_input_succed = "Your User name and Pass wort has been set!";

string Exit = "Yes";
string Test;

string Question = "Enter Yes if you want to Exit";


int main () //Start Main Function
{


  ofstream User; //open ofstring

  User.open ("Testing.dat"); //open file to write

  cout << Enter_Username; //open string to write into database
  //cin >> User_input;  //Detect user input
  getline (cin, User_input);
  User << "Username: " << User_input << endl; //print string and write input in file

  cout << Enter_Passwort; //open string to write into database
  //cin >> User_input_1; //Detect user input
  getline (cin, User_input_1);
  User << "Passwort: " << User_input_1;//print string and write input in file

  cout << endl << User_input_succed << endl; //print string
  User.close ();  //close file

  do      //start Exit command

  {
    cout << Question << '\n'; //print string
    cin >> Test;  //Wait for User input

  } while (Exit != Test); //compare user input with Exit if not equal continue if equal exit program

  system ("pause");
  return EXIT_SUCCESS;
}

OUTPUT
--------
Enter Your desired User name
Anna Pogany
Enter Your desired Pass wort
ABC DEF

Your User name and Pass wort has been set!
Enter Yes if you want to Exit
Yes
Press any key to continue . . .
Thanks, I done it like: cin.getline(User_input,15)

That solved everything :)
Topic archived. No new replies allowed.