Runtime error (attempting simple caeser cipher)

Hi I am in the process of coding a caeser cipher and when am currently getting a runtime error that I cannot find the cause of, and can't really continue the code until i solve this issue.

the code is somewhat sloppy since it is in the early stages but if anybody could sift through the code and maybe find the issue, it would be much appreciated.

I cant copy the output data due to the error forcing a close but it says

...

This program has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <string>

using namespace std;

class EncryptString : public string{
private:
        string message;
	    char* newChar;
        int stringlength;
	    char currentChar[100]; 
public:
       EncryptString(){stringlength=0;
                                      }
       EncryptString(string msg){stringlength=msg.length();
                            message=msg;
                                                          }
                                                             
	void encrypt();
	void decrypt();
	char testdecrypt();
	int getstringlength();


};

int EncryptString::getstringlength(){
    return stringlength;
}

void EncryptString::encrypt(){
for(int i=0;i<100;i++){
				currentChar[i]=this->at(i);
				
                            }               
}


char EncryptString::testdecrypt(){
                                  for(int l=0;l<100;l++){
                                          return currentChar[l];
                                          
                                          }}
void EncryptString::decrypt(){

}

int main (){

cout<<"Please enter a string to be encrypted."<<endl;
string message;
getline(cin,message);

EncryptString emessage(message);
int len= emessage.getstringlength();
cout<<len<<endl;


emessage.encrypt();
cout<<"This is the message you entered."<<endl;



char store[len];

store[len]=emessage.testdecrypt();

for(int p=0;p<len;p++){
                       cout<<store[p]<<endl;
                       }



system ("pause");



}


thanks for any assistance :)
appears to be an out of scope issue for this->at(i)

i do not know how to bring it into scope though :/
When you do this: for(int i=0;i<100;i++) you need to keep within the bounds of the data. Try using i<this->size() instead of i<100 as the test condition.
Topic archived. No new replies allowed.