strings? cant figure out my mistake?


[#include<iostream>

#include<fstream>
#include <cstring>
using namespace std;

int main()
{
char s1[20];
cout<<" enter string: ";
cin.get( s1);

cout << " s1 is: " << s1;
return 0;
}]

[/code]
Last edited on
http://www.cplusplus.com/reference/istream/istream/get/
If you're expecting to read a string, you also need to pass the length of your array.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
#include<fstream>
#include <cstring>
using namespace std;

int main()
{
	char s1[20];
	cout << "Enter string: ";
	cin.getline(s1, 20);

	cout << "\ns1 is: " << s1;
	system("pause"); 
	return 0;
}
oh i see thanks!
Topic archived. No new replies allowed.