Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error C2228 with substr

Status
Not open for further replies.

cadbilbao

Programmer
Apr 9, 2001
233
ES
Hi!

I'm using VC++ 6.0. I want to create a substring (name) from another string (infile):

---------------//---------------

#include <string.h>

....

void dodo(char *infile) {
char name;
int lgt;

lgt = strlen(infile);
name = infile.substr(5,10);
}
--------------//------------------

But I get this error:
error C2228: left of '.substr' must have class/struct/union type

What am I doing wrong?

Regards.
 
Well, since when has C had objects? A char* can't call functions on itself via the dot operator. The error C2228: left of '.substr' must have class/struct/union type is telling you that char* is not a class/struct/ or a union, which it isn't so remove it.

bitwise
 
Be attentive, substr is not a member of char*. Maybe for C++ classes like string, CString, strsrteam... it is not an error. John Fill
1c.bmp


ivfmd@mail.md
 
The above programers are right.
Your program should look something like this:

#include <string.h>

....

void dodo(char *infile) {
char name[100];
name[0]='\0';
strncpy(name,infile+5,5); //if you want 5 caracters
}

Hope this helps,s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top