Click to See Complete Forum and Search --> : String in C++


qwe
10-03-2002, 08:12 AM
I am trying to use a function to save a word to a global string, depending on what the user input was.
the code goes like this:

char g_string[255]; //declare global sting
int main(void)
{
//main program
}

int changestring(int y)
{
switch (y)
{
case 1:
{
strcpy (g_string, "word to be used");
break;
}
case 2:
{
strcpy (g_string, "other word");
break;
}
}
return 0;
}


When I compile, I get the message 'strcpy' is 'unidentified'
what am I doing wrong?
please help.
thanx.

rock
10-03-2002, 08:44 AM
I think you need to #include <string.h>

Pinky
10-03-2002, 12:01 PM
Yep, you need either

#include <string.h>
or
#include <string>
using namespace std;


Also, you can try using the actual C++ string type as well instead of using an array. Just declare some variable string variablename.

qwe
10-03-2002, 12:38 PM
Thanx guys, I'll try that

dighn
10-05-2002, 06:01 AM
Originally posted by Pinky
Yep, you need either

#include <string.h>
or
#include <string>
using namespace std;


Also, you can try using the actual C++ string type as well instead of using an array. Just declare some variable string variablename.

just a nitpick but <string> in c++ is for the class std::string, for c string functions like the ones found in c's string.h, use <cstring>

Nephalim
10-05-2002, 12:45 PM
I think the problem lies in this little distraction -> g_string
:P sorry... too much coffee this morning... too little food.