Using a word in C++

I'm having a problem scripting a program in C++. My goal is to have a basic username and password input/output system. I haven't been doing this very long so I don't know everything. I'm still cramming with tutorials and manuals before I get into college in the spring, so please understand my ignorance on this subject.

I am attempting to have a program that (step-by-step) accepts two usernames and passwords and then prints them onto the screen. It's just an exercise, I know it's not practical.

My issue is that I can't seem to store and release a full word. 'Int' doesn't work for obvious reasons, and when I use 'char' it only saves the first character. I've tried using 'std::string' which works halfway, but only outputs a sequence of numbers. I'm sure I'm doing something wrong and that this is just a beginner's mistake, but if I could get some help, that would be awesome.

Here's a sample of the code so you understand a little better:

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
  #include <iostream>
#include <string>
using namespace std;

struct users
{
	? ? ? Username[20];
	? ? ? Password;
};

int main()
{
	? ? ? Username1;
	? ? ? Password1;

	cout << "Please enter your Username: ";
	cin >> Username1;
	cout << "\nPlease enter your Password: ";
	cin >> Password1;
	users user1info =
	{
		Username1,
		Password1
	};

	cout << "\nYour info is: ";
	cout << user1info.Username << "\n" << user1info.Password << "\n\n\n\n";
	return 0;
}
Last edited on
Replace ??? with string, AND get rid of [20]. Otherwise it is an array of strings
I'm not going to lie, it's a little disappointing that the solution was as simple as removing the [20]. I was following a guide and it said to have that, I tweaked the script a lot so-as-to make my own program, but it didn't even occur to me to change that. It works perfectly not, thank you.
Topic archived. No new replies allowed.