Valhalla Legends Forums Archive | C/C++ Programming | [C++] Visual Studio Exploded

AuthorMessageTime
R.a.B.B.i.T
I can't figure out what went wrong, because this works at school and at my friend's house.  Reinstalling didn't work.  Getting SP's didn't work.  I'm out of ideas...

[quote]--------------------Configuration: rawr - Win32 Debug--------------------
Compiling...
rawr.cpp
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(59) : error C2065: 'strlen' : undeclared identifier
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(62) : error C2065: 'strcpy' : undeclared identifier
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(346) : error C2065: 'strncmp' : undeclared identifier
e:\program files\microsoft visual studio\vc98\include\lvp\string.cpp(374) : error C2065: 'strcmp' : undeclared identifier
Error executing cl.exe.

rawr.exe - 4 error(s), 0 warning(s)[/quote]
Offending lines:
[code]String::String(const char * s)
{
assert (s != 0);

myLength = strlen(s); // offending line 59
    myCapacity = myLength + 1;
    myCstring = new char[myCapacity];
    strcpy(myCstring,s); //offending line 62
}

int String::find(const String & str)  const
{
    int len = str.length();
    int lastIndex = length() - len;
    int k;
    for(k=0; k <= lastIndex; k++)
    {
        if (strncmp(myCstring + k,str.c_str(),len) == 0) return k; // offending line 346
    }
    return npos;
}

bool operator == ( const String & lhs, const String & rhs )
{
    return strcmp(lhs.c_str(), rhs.c_str()) == 0; // offending line 374
}[/code]

The library I am using is here: http://www.lvp.com/data/cpluspc/
November 6, 2004, 10:06 PM
UserLoser.
Why not use string.h?
November 6, 2004, 10:53 PM
Newby
Or why not just use a regular character array?
November 6, 2004, 11:04 PM
R.a.B.B.i.T
string.h dislikes me more than the LVP library.

Character arrays cannot be passed as reference.

[edit]
Updated the strcmp libraries and whatnot (after a couple hours on google), it works now.
November 7, 2004, 3:06 AM
Newby
[quote author=R.a.B.B.i.T link=topic=9451.msg87720#msg87720 date=1099796816]
Character arrays cannot be passed as reference.
[/quote]
As far as I can remember, if you pass the address of the first character in the array, it'll technically be passed as reference.

[code]#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void SomeSub(char *Buffer)
{
strcpy(Buffer, "Rabbit sux");
return;
}

int main()
{
char Buffer[48];
SomeSub(Buffer);
printf("%s\n", Buffer);
system("pause");
return 0;
}[/code]
Output: Rabbit sux

Took me ~2 minutes to write.

So eh?
November 7, 2004, 3:30 AM
R.a.B.B.i.T
But that requires you to predefine a string length.
November 7, 2004, 3:51 PM
Newby
[quote author=R.a.B.B.i.T link=topic=9451.msg87771#msg87771 date=1099842703]
But that requires you to predefine a string length.
[/quote]
Oh noes?

Why not just allocate space as needed like this?

[code]char *Buffer = new char[1048][/code]

Again, I'm not sure if that's exactly it, but it's something along those lines.

And this has been discussed before, on how to resize character arrays.
November 7, 2004, 4:47 PM
Mephisto
Be careful in your terminology Newby & Rabbit.  A passing a reference and passing by reference are two different things.  Passing by reference can be accomplished by either passing the address or a pointer pointing to the data or passing a reference variable to the data.  A reference is that variable.  Passing by reference is passing that reference or address into the function which can be accomplished with references or pointers.  Also note that character arrays (and arrays in general) are passed by reference by default (their addresses are passed into the function, not copied).
November 7, 2004, 6:59 PM

Search