C++ programming. Please Help!!!!

This program is supposed to read what user inputs backword. The errors I get are:
Line 33: expected primary-expression before ']' token
Line 34: expected primany-expression before ']' token

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
#include<iostream>  
#include<string>     

using namespace std;  

int main() {
     string str;
     typedef char* CharHead;
     CharHead head; 
     typedef char* CharTail;
     CharTail tail;
     typedef char* CharCstr;  
     CharCstr cstr;
    
     int i = 0;     

     cout << "Enter a string: ";  
     getline(cin, str);  

     cstr = new char[str.size() + 1];  
     strcpy(cstr, str.c_str());  

     head = &cstr[0];  
     tail = &cstr[str.size() - 1];  
     
     cout << "String inverted is: "; 
     
     typedef char* CharTemp;  
     CharTemp temp;

while (head <= tail) // this should be done only halfway of string and not for complete string, as you are swapping them now.  
{  
     temp = cstr[]; 
     cstr[] = tail;  
     tail = temp;  
     tail--;  
     head++;  
     i++;  
}  
       
    cout << cstr;  
    cout <<"\n"; 
    system ("PAUSE");
    return 0;  

} 
Anyone??
I think it expects an integer between the []'s.
if I put integer, I get the error:
Line 33: invalid conversion from 'char' to 'char*'
Line 34: invalid conversion from 'char' to 'char*'
I can't use pointer arthimetic, this is why I need to do it this way.
anyone?
if I put integer, I get the error:
Line 33: invalid conversion from 'char' to 'char*'
Line 34: invalid conversion from 'char' to 'char*'

The compiler is complaining that those assignments don't make sense. Applying the array subscript operator to a char* gives you a char, which you try to assign to/from a separate char*.
Topic archived. No new replies allowed.