First, there is a difference between a char and a string.
A char is just a single-byte integer. (it might be signed or unsigned, but we'll ignore that for now). A constant like
'a'
or
'2'
is a char whose ASCII value is the value for 'a' or '2'. In other words, these two statement are the same:
1 2
|
char ch = 65; // 65 is the ASCII encoding for 'A'
char ch = 'A';
|
Now the compiler also lets you put together an array of chars that represent the ASCII encoding of a bunch of characters. For example, these are all the same
1 2 3
|
char *cp = "ABC";
char *cp = {'A', 'B', 'C', 0};
char *cp = {65, 66, 67, 0};
|
The 0 at the end of the last two a convention used by C and C++ to indicate the end of an array of chars when the chars represent ASCII characters. We call this a "null-terminated string" because it end with 0, which is often referred to as null.
Are you with me? The important thing here is that
char is just a one-byte integer.
The char arrays I showed above have a big drawback: their size is fixed at compile time. Lots of real world problems require us to deal with strings of varying sizes. We add text to them, replace text, delete it, change it, etc. etc. Rather than making everyone write their own code for doing this (and frequently getting it wrong!), the Standard Library has a class that does all the details under the hood.
This class is string. It manages an array of char and handles all the memory management for you.
Now you can create a string like this:
string s = "This is a string";
and you can access each char within it. s[0] is the first character, s[3] is the 4th etc.
So I think you need to write your program from the bottom up. First, create a function that takes a char and a shift count, and does a caeser cypher shift of the char, by the shift count. I mentioned how to do this in a previous post.
Then create a function that takes a string and calls the caesar function on each character in the string.
Hope this helps.