Stack Around Input is Corrupted Error- Why?

I'm trying to read input and store it into a character array. It works up to the point that I enter the stream of characters and press enter. Then the program breaks, and a windows pops up and says "Stack Around Input is Corrupted." I'm wondering why this runtime error comes up.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "stdafx.h"
#include "iostream"
#include "windows.h"

using namespace std;
int main()
{
	int i=0; //so far this does nothing
	char input [5];
	
	//intro
	cout<<"Welcome to the Text/Phone Number Converter!\n";
	cout<<"This program will convert seven characters of text into their numeric equivalent. \nNumbers will be left as-is.\n";
	Sleep(2000);
	cout<<"Please enter your desired string: \n";
	cin>>input[1]>>input[2]>>input[3]>>input[4]>>input[5]>>input[6]>>input[7];
	cout<<input[1]<<input[2]<<input[3]<<input[4]<<input[5]<<input[6]<<input[7];
	cout<<"Please enter any key to continue.";
	cin.get();


	return 0;
}


EDIT: I found the error. I created the character array for 5 characters, but tried to get seven. My bad.
Last edited on
Topic archived. No new replies allowed.