Reading an int from a string

Hello, I am working on a decryption project, and I am trying to decode this message using a Caesar Cipher method.

13nggnpxongx3933&7#10


"13" being my shift number,

"nggnpxongx3933" being the message to be decoded,

and

"7" and "10" being the location of the spaces in the original message.

Now, my question is how would I make "13" an integer, so that I can have my shift number as an int?

any help would be great!

The original message is "attack at 0600"

code so far:

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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
	string message, decrypt, n;
	int count, m, d;
	ifstream input;
	
	
	//read encrypted message from "secret.dat"
	input.open("secret.dat");
	getline(input, decrypt, '&');
	getline (input, message);
	input.close();
	
	
	cout << "encrypted message is: " << decrypt << endl;
	
	m = message.length();
	d = decrypt.length();
	
	
	for (count = 0; count < d; count++)
	{			
		if (isalpha(decrypt[count]))
		{
			decrypt[count] = tolower(decrypt[count]);
			for (int i = 0; i < 13; i++)
			{
				if (decrypt[count] == 'a')
					decrypt[count] = 'z';
				else
					decrypt[count]--;
			}
		}
		
		if (isdigit(decrypt[count]))
		{
			for (int i = 0; i < 13; i++)
			{
				if (decrypt[count] == '0')
					decrypt[count] = '9';
				else 
				decrypt[count]--; 
			}
		}
	}
	
	cout << decrypt << endl;
	cout << message << endl;

	return 0;
	
}
http://www.cplusplus.com/reference/string/stoi/?kw=stoi
http://www.cplusplus.com/reference/string/string/substr/

The first is a link to how to turn a string numer into an int, and the second link is for how you might grab the number by itself after you determine how long it is.
Last edited on
create a function to check each char of a string and see if it's a '0', '1' and so on.
Topic archived. No new replies allowed.