I want to request the a username and password from 6 users,
and then save this username and password into a text file on my desktop.
I built a structure that has one variable to store the password and a char
array with a length of 25.
struct users {
int password;
char username[25];
}
When I want to request the username in the main()
function, I use the cin.get()
function.
cin.get(username,25);
The program stops after the second cin
function when it is storing the password. Why is that?
#include <iostream>
#include <fstream>
struct users {
char username[25];
int password;
} user[6];
using namespace std;
int main() {
cout << "Sign up x6" << endl;
for(int i=0;i<6;i++){
cout << "Username:";
cin.get(user[i].username,20);
cout << "Password:";
cin >> user[i].password;
}
std::ofstream file;
file.open("C:/Users/Programmer/Desktop/sa.txt",ios::app);
for(int i=0;i<6;i++){
file << "first user\n" << user[i].username << endl << user[i].password << endl;
cout << "\n \n \n";
}
}
thank you for your help .. – Yasser A. ElShbrawy Nov 25 '17 at 00:33