Increase char from a to b (or c to d)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream> 
using namespace std; 
 
 
int main () 
{ 
    char character = 'a';
    char * pointera;
    char * pointerb;
    pointera = &character;
pointerb = *pointera;
    *(++pointerb);
    cout << pointerb;
}


the point of this code is to increase character by 1 (so from a to b in this case).
The underlined line is the line that the system is rejecting at the moment (but there may be other issues). Please can someone explain why it is invalid?

thanks
Last edited on
It's pretty pointless telling us "the system is rejecting it".

The error message from your compiler should be something like

error C2440: '=' : cannot convert from 'char' to 'char *'

which should give you a rather large clue .

But that wont fix your issue. Why are you wanting to do it like this?
Last edited on
1
2
3
4
5
6
7
8
#include <iostream> 

int main () 
{ 
    char character = 'a';
    ++character;
    std::cout << character;
}
MiiNiPaa...thanks
i never realised it was that simple. I was overconfusing it
you can also write this code

1
2
3
4
5
6
7
#include <iostream>

int main()
{
    char a='a'+1;
    cout<<a;
}
Last edited on
but if want to do in your way
you cant write this

1
2
3
4
5
6
7
int main()
{

    int a=98;     //look at the ASCII table
    char b=a;
    cout<<b;
}
@justinelandichoruiz And what if user does not use ASCII?
@MiNiiPaa that's why I gave him ASCII code and non ASCII code
thanks all :)
Topic archived. No new replies allowed.