Pointers and string trouble

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackstormdragon
    New Member
    • Feb 2007
    • 32

    #1

    Pointers and string trouble

    My trouble causing lines are maked within the code.
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    void main()
    {
    	string* head;
    	string* tail;
    	head = new string;
    	tail = new string;
    
    	string reString;
    
    	cout<<"Enter a some content you want reversed: ";
    	getline(cin,reString);
    
    
    	head* = reString[index];//problem here
    	tail* = reString[index2];// and here
    Though I don't show it index and index2 have been initialized. The lines that I've marked are giving me the error C2059: syntax error : '='. I have no clue what that means. I've tried removing the *, but that only gives me a different error. It proably dosen't help that Im not good with pointers.
    Helps appreciated, thanks.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Use head = &reString[index], or (*head) = reString[index]. Not sure which of those will work, but one of them sure will.

    Comment

    • kaioshin00
      New Member
      • Nov 2006
      • 46

      #3
      Originally posted by blackstormdrago n
      My trouble causing lines are maked within the code.
      Code:
      #include<iostream>
      #include<string>
      using namespace std;
      
      void main()
      {
      	string* head;
      	string* tail;
      	head = new string;
      	tail = new string;
      
      	string reString;
      
      	cout<<"Enter a some content you want reversed: ";
      	getline(cin,reString);
      
      
      	head* = reString[index];//problem here
      	tail* = reString[index2];// and here
      Though I don't show it index and index2 have been initialized. The lines that I've marked are giving me the error C2059: syntax error : '='. I have no clue what that means. I've tried removing the *, but that only gives me a different error. It proably dosen't help that Im not good with pointers.
      Helps appreciated, thanks.
      Remember pointers are supposed to contain address values. I'm not really sure what your program is supposed to be doing, but you should be assigning head and tail address values of strings.

      Comment

      • blackstormdragon
        New Member
        • Feb 2007
        • 32

        #4
        Thanks the (*head) one worked, I belive my star was in the wrong place. Thanks, I miss little things like that alot.

        Comment

        Working...