 |
 |
CC header libraries?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status:
Offline
|
|
I'm a newbie taking a class in C++, so if anybody can help me, I would appreciate it.
cstring.h is supposed to be included when using strings.
When compiling with cc on OS X, I get the error:
test.cpp:15: cstring.h: no such file or directory.
I can include iostream.h and math.h without problems, but it can't find cstrings.h?
I think the error has to do with the compiler not finding the libraries?
If this is true, how would I 'link' the libraries?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
I have never heard of cstring.h if the functions that you are using are named like strcmp or strcat then they should be part of the string.h. If it can't find any of those just try using your functions without including anything for them. The compiler links against a number of standard libraries, such as pthreads.h, without you telling it to so you should be fine if cstring.h is part of the standard set of c libraries.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status:
Offline
|
|
I apologize if I wasn't clear. Did I mention I'm new at this?
My class requires the Borland C++ Compiler under windows. I have been attempting to use Apple's cc Compiler instead.
What I have been taught is to use cstring.h in order to use strings in a C++ program. This might be just for the Borland compiler. I don't know, and I can't find any information on it. If you could refer me to somewhere with clear information, that might be helpful.
But when I attempt to use strings and compile it with cc, I get a bunch of errors, so it seems that I need a header library. cstring.h isn't accepted.. and not including anything or including string.h just leaves me with an error like this:
mcn_2.cpp: In function `int main()':
mcn_2.cpp:38: `string' undeclared (first use this function)
mcn_2.cpp:38: (Each undeclared identifier is reported only once
mcn_2.cpp:38: for each function it appears in.)
mcn_2.cpp:38: parse error before `;'
mcn_2.cpp:39: `nick' undeclared (first use this function)
I THINK this means it can't figure out what strings are, as it compiles just fine in Borland c++.
thanks for your help.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Apr 2001
Status:
Offline
|
|
Post your program. We can help you figure out what you need.
Wade
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
use c++ to compile and in final ANSI/ISO C++ you use #include <iostring> and <cstring>, not .h, I don't think. That was what was used in earlier implementations.... At least I thnk that'w aht I read in my big C++ book 
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status:
Offline
|
|
Right now, I have about 5 'class project' programs which use strings. All of them seem to compile just fine in Borland C++. Yet, all of them give me the similar errors. It either states "test.cpp:15: cstring.h: no such file or directory." or chokes with a bunch of errors if #include <cstring.h> is commented out.
I've tried #include <cstring>, but that also results in errors. I always use the command c++ from the terminal if that makes any difference.
A quick and dirty sample program here. Borland C++ will compile this. Apple's cc won't. :
#include <iostream.h>
#include <cstring.h>
int main(void) {
string sHello;
sHello = "hello there";
cout << sHello << endl;
return 0;
}
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Try #include <string> - cstring is for the C string functions like printf(), I think.
When I reboot into OS X i'll have a go at compiling it or something.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2001
Status:
Offline
|
|
#include <string> will work. I was using it just the other day to do some C++ programming for a class. Your compiler is c++, also note there is a bug in it when doing input. If you want a console prompt for input, you must end the line if you want it to display before the console waits for input.
ie:
#include <iostream>
#include <string>
using namespace std;
// Read and display data.
int main()
{ string input;
cout << "Type a word: ";
cin >> input;
cout << "You typed: " << input << endl;
return 0;
}
needs to be changed to:
#include <iostream>
#include <string>
using namespace std;
// Read and display data.
int main()
{ string input;
cout << "Type a word: " << endl; // note the endl; here, this is the change
cin >> input;
cout << "You typed: " << input << endl;
return 0;
}
Just a little heads up on a glitch to come. Compile and run each to see specifically what I mean. Apple needs to do a little work on the c++ compiler. :-)
Ryan C.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status:
Offline
|
|
#include <string> works.
Thanks for everything.
Now I can test and debug without having to use realpc =)
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|