1,105,281 Community Members

error C2228: left of '.c_str' must have class/struct/union

Member Avatar
RAIMI
Newbie Poster
13 posts since Jul 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi!
I try to compile this code

while( file >> word) 

 {
	 word.size();
	 T[i]= new string[word.size()];
	 *(T[i])= word;

		i=i+1;

 }
 for (j=0;j<i;j++)
  { Bt[j] = new float [100];
	*Bt[j] = *atof(*(T[j]).c_str()); 
	
  }

but i have this problem

error C2228: left of '.c_str' must have class/struct/union

where

float **Bt ;
string  **T;

how can i fix this problem?

Member Avatar
Narue
Bad Cop
12,139 posts since Sep 2004
Reputation Points: 5,693 [?]
Q&As Helped to Solve: 1,537 [?]
Skill Endorsements: 80 [?]
Team Colleague
 
0
 

>*(T[j]).c_str()
Check a precedence table. Member access has higher precedence than indirection, so you're still trying to call c_str() on a pointer. The arrow operator saves you from having to remember that rule though:

T[j]->c_str()
Member Avatar
RAIMI
Newbie Poster
13 posts since Jul 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks it's work

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article