home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,153 of 33,346   
   Edward Diener to news.eternal-september.org   
   Re: why can't i access std::string with    
   16 Apr 12 23:44:09   
   
   From: eldiener@tropicsoft.invalid   
      
   { Please restrict your quoting to the minimum needed to   
   establish context -mod/we }   
      
   On 4/16/2012 6:09 PM, news.eternal-september.org wrote:   
   > Hello,   
   >   
   > I'd like to access C++ strings the way i did in C , that is:   
   > char foo[]="foo"; //foo[0] foo[1] ...   
   >   
   > I read several times that [] was allowed for string access.   
   > Unfortunately, i think i'm missing something.   
   >   
   >   
   >   
   > #include    
   > #include    
   >   
   > using std::string;   
   >   
   > int main(void)   
   > {   
   > string foo="foo";   
   > string bar="bar";   
   >   
   > string result = "and ? ";   
   > result += foo[1] + bar[2];   
   > std::cout << result << "\n"; //result should be "or"   
   >   
   > return 0;   
   > }   
   >   
   >   
   > Thank you for reading.   
   >   
   >   
      
   Why do you think that foo[i] + bar[2] becomes "or" ?   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca