Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > CC header libraries?

CC header libraries?
Thread Tools
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status: Offline
Reply With Quote
Apr 19, 2001, 03:56 PM
 
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
Reply With Quote
Apr 23, 2001, 04:40 PM
 
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.
     
bree  (op)
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status: Offline
Reply With Quote
Apr 23, 2001, 05:27 PM
 
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
Reply With Quote
Apr 23, 2001, 11:26 PM
 
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
Reply With Quote
Apr 24, 2001, 03:39 PM
 
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
     
bree  (op)
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status: Offline
Reply With Quote
Apr 24, 2001, 11:53 PM
 
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
Reply With Quote
Apr 26, 2001, 01:52 AM
 
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
Reply With Quote
Apr 26, 2001, 09:46 AM
 
#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.
     
bree  (op)
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neverwhere
Status: Offline
Reply With Quote
Apr 26, 2001, 11:50 PM
 
#include <string> works.
Thanks for everything.
Now I can test and debug without having to use realpc =)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2