string problem

i am just start learning string
and this program allow user to enter id and will show what id user enter
but if user enter "0001"
the program just show "1"
so how can i solve this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string id[2];
	for (int a=0;a<1;a++)
	{
	cout<<"enter your id :";
	cin>>id[a];
	cout<<id[a]<<endl;
	}
	system("pause");
	return 0;
}
Last edited on
Modify line 7 for 2 values for a. Also, id[] is an array of integers so its content will be of...integers, e.g: 1, -3 etc. Try to use for id[] string not int.
Last edited on
now the problem solve
but i wan to if else statment
example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>

using namespace std;
int main()
{
	string id[2];
	istringstream buffer();
	for (int a=0;a<1;a++)
	{
	cout<<"enter your id :";
	cin>>id[a];
	cout<<id[a]<<endl;
	if (id[2]=='0001')//problem here
		cout<<"success";
	else
	cout<<"fail";
		
	}
	system("pause");
	return 0;
}

the problem is i can let the if else statment to be complete
how to solve it?
Firstly: in the line 14 need id[0] not id[2].

Secondly: id[] is an array of strings so you must put "0001" not '0001' as in lines 15, 17 and 20.

I hope this helps...
Last edited on
thank a lot
this really help me
You're welcome!
Topic archived. No new replies allowed.