Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

In my program I got this error C2039: 'size' : is not a member of 'CString'.
How to solve it? help me.
C++
BOOL CEMailDlg::Validate() 
{  
	CString m_sFrom;
	
	for(int a = 0; a < m_sFrom.size(); a++) 
	{  
		if(m_sFrom.at(a) = '@') 
			return true;
   }   return false;
}

thank you
Posted
Updated 9-May-11 23:43pm
v2

Did you mean to use GetLength? MSDN[^]

for(int a = 0; a < m_sFrom.GetLength(); a++)
 
Share this answer
 
Comments
[no name] 10-May-11 6:24am    
I just wonder what part of the error message he did not understand. Then again, not everybody can be a master of the obvious.
OriginalGriff 10-May-11 6:30am    
That's me! Master of the Obvious! :)
It's nice to be recognised as Master of Something... :laugh:
[no name] 10-May-11 6:34am    
'Master of the Obvious' usually is not meant to be a title of honor and prestige and usually bestowed upon people who can't think their way out of a paper bag. I would not want to use it for you, but if you insist...
If memory serves: try m_sFrom.GetLength() instead

EDIT: Just read the code - for what you are trying to do wouldn't it be better to use:

return (m_sFrom.Find( '@' ) != -1)


instead of searching manually?
 
Share this answer
 
v2
"size" and "at" is a member function of basic_string.
1) include basic_string header file
#include <string>
using namespace std;

Replace CString m_sFrom; with string m_sFrom;


2) If you still want to use CString than

BOOL CEMailDlg::Validate() 
{  
	CString m_sFrom;
	
	for(int a = 0; a < m_sFrom.GetLength(); a++) 
	{  
		if(m_sFrom.GetAt(a) == '@') 
			return true;
   }   return false;
}
 
Share this answer
 
v4
Comments
degorio 10-May-11 9:04am    
im getting this error ,,error C2628: 'CString' followed by 'int' is illegal (did you forget a ';'?)... how to solve it
ShilpiP 10-May-11 9:18am    
No one mistake I found in my code is using assignment instead of ==
if(m_sFrom.GetAt(a) == '@')
return true;
Replace size() by GetLength().
Everything is written in MSDN. Check out the documentation for the CString class.
 
Share this answer
 
Comments
degorio 10-May-11 9:29am    
im getting this error ,,error C2628: 'CString' followed by 'int' is illegal (did you forget a ';'?)... how to solve it
Olivier Levrey 10-May-11 9:36am    
Post the code please. The code you posted in your question doesn't match the error you describe.
degorio 10-May-11 9:41am    
BOOL CEMailDlg::Validate()
{
CString m_sFrom;
int a;
int GetLength();
for( a=0;a < m_sFrom.GetLength(); a++)
{
if(m_sFrom.GetAt(a) == '@')return true;
}
return false;
}
Olivier Levrey 10-May-11 9:43am    
Remove the int GetLength(); line.
degorio 10-May-11 9:45am    
the same error occurs
This is a simple error...

Then I understand that you are novice... so I'll give you some tricks:

- When working with objects, pressing "." will show you up the intellisense which should help you to find the right method.
- Each object type is based on a class... i.e. you have a CString (class) named m_sFrom (object). So you can search help (MSDN, google, Here...) to get details on how to work with i.e. strings looking for CString.

Apart from that OrigianlGriff has given you a proper answer... (joke to OG => Obvious ;P but proper)...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900