By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Pointers and string trouble

blackstormdragon
P: 32
My trouble causing lines are maked within the code.
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. void main()
  6. {
  7.     string* head;
  8.     string* tail;
  9.     head = new string;
  10.     tail = new string;
  11.  
  12.     string reString;
  13.  
  14.     cout<<"Enter a some content you want reversed: ";
  15.     getline(cin,reString);
  16.  
  17.  
  18.     head* = reString[index];//problem here
  19.     tail* = reString[index2];// and here
  20.  
  21.  
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.
Oct 4 '07 #1
Share this Question
Share on Google+
3 Replies


Ganon11
Expert 2.5K+
P: 3,652
Use head = &reString[index], or (*head) = reString[index]. Not sure which of those will work, but one of them sure will.
Oct 4 '07 #2

P: 46
My trouble causing lines are maked within the code.
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. void main()
  6. {
  7.     string* head;
  8.     string* tail;
  9.     head = new string;
  10.     tail = new string;
  11.  
  12.     string reString;
  13.  
  14.     cout<<"Enter a some content you want reversed: ";
  15.     getline(cin,reString);
  16.  
  17.  
  18.     head* = reString[index];//problem here
  19.     tail* = reString[index2];// and here
  20.  
  21.  
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.
Oct 4 '07 #3

blackstormdragon
P: 32
Thanks the (*head) one worked, I belive my star was in the wrong place. Thanks, I miss little things like that alot.
Oct 4 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.