GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rating: Thread Rating: 5 votes, 5.00 average.
  #1  
Old 03-Jul-2005, 19:34
Atomical Atomical is offline
New Member
 
Join Date: Jul 2005
Posts: 25
Atomical has a little shameless behaviour in the past

problem with include


As soon as I take this function out of main and put it in another file named html.cpp it gives me this error: error: string was not declared in this scope.
It does this on the void proc_html line...

CPP / C++ / C Code:
#include <iostream>
#include <string.h>
#include <iostream>
#include <ctype.h>
#include <stdio.h>




void proc_html (string html) {


storage freezer[7];

freezer[0].storage = "href=";
freezer[0].len = 5;
Last edited by LuciWiz : 03-Jul-2005 at 22:33. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 03-Jul-2005, 19:49
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,621
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Atomical
As soon as I take this function out of main and put it in another file named html.cpp it gives me this error: error: string was not declared in this scope.

Each file is a separate compilation unit. If a file uses strings, the string header must be #included in that file.

You should use standard headers. Note that the C header <string.h> contains functions like strcpy(), strcat(), etc. When this header is used with C++, you should #include <cstring>, not <string.h>.

Also when using the functions in the C header <stdio.h> in a C++ program, you should #include <cstdio>. Similarly, other C library headers, like <ctype.h> are renamed for c++ to things like <cctype>.

Note that the C++ string class and its functions are defined in the C++ header <string>, not <string.h>, and not <cstring>.

There are a few other issues that you must be at least aware of with the C++ headers. These headers define functions that are in a special namespace, called std.

So, the front end of your files might look like this:

CPP / C++ / C Code:
#include <iostream>
#include <string>
#include <iostream>
#include <cctype>
#include <cstdio>

using namespace std; // Consider this to be an idiom until you learn more about namespaces

Of course you only neet whatever headers are needed by the library functions and classes in that particular file.

If you have been using the c-style headers in your c++ programs and they seem to have been working, it's something that compilers up until now have been supporting, but they may not do so in the future. That's why I urge you to start using standard C++ headers.


Regards,

Dave
  #3  
Old 03-Jul-2005, 20:10
Atomical Atomical is offline
New Member
 
Join Date: Jul 2005
Posts: 25
Atomical has a little shameless behaviour in the past
All my includes are in that file too.. I even included the proto. I'm on Mac OS X and none of those libraries that you suggested appear to exist.
  #4  
Old 03-Jul-2005, 20:48
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,621
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Atomical
All my includes are in that file too.. I even included the proto. I'm on Mac OS X and none of those libraries that you suggested appear to exist.

I'm sorry; I was referring to Standard C and Standard C++. I don't have access to a Mac for testing, but since OS X is based on freeBSD, I am quite sure that standard C and Standard C++ headers must be available. If you can't #include <cctype>, for example, then I think that either your installation is broken, or you don't have proper environment variables set up for compilation and linking.

Maybe someone else reading this thread can help.

Sorry.

Regards,

Dave
Last edited by davekw7x : 03-Jul-2005 at 21:22.
  #5  
Old 03-Jul-2005, 21:07
Atomical Atomical is offline
New Member
 
Join Date: Jul 2005
Posts: 25
Atomical has a little shameless behaviour in the past
CPP / C++ / C Code:
#include <iostream>
#include <cstring>
#include <iostream>
#include <cctype>
#include <cstdio>

I changed these and got the same error.
Last edited by LuciWiz : 03-Jul-2005 at 22:35. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #6  
Old 03-Jul-2005, 21:23
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,621
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Atomical
#include <iostream>
#include <cstring>
#include <iostream>
#include <cctype>
#include <cstdio>

I changed these and got the same error.


Did you put the following line after the #includes?

CPP / C++ / C Code:
using namespace std;

Regards,

Dave
  #7  
Old 04-Jul-2005, 07:27
Atomical Atomical is offline
New Member
 
Join Date: Jul 2005
Posts: 25
Atomical has a little shameless behaviour in the past
I put that in there, still nothing.
  #8  
Old 04-Jul-2005, 08:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,621
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Atomical
I put that in there, still nothing.


If I understand the problem so far:

1. You can make a program with everything in a single file that uses C++ strings.

2. When you put some functions in one file and others in a different file, the only compiler error message is that string is undefined in the scope for one of the files.

Let's try this: Make two small files that illustrate this problem and post them. Copy and paste the actual source text into your response Use code tags, as shown here: Guidelines for posting requests for help

Tell me how you compile and link the files on the Mac. I can't recreate your environment, but I may be able to tell what's happening.

No guarantees, but I don't mind trying (until someone on this forum with a Mac jumps in and gives you specific advice).

Regards,

Dave
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
savings account problem ap6118 CPP / C++ Forum 5 01-Apr-2005 09:37
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 07:10
help with classes bucho MS Visual C++ / MFC Forum 3 20-Oct-2004 06:16
Hmm what seems to be the problem here? error C2061: syntax error pablowablo CPP / C++ Forum 5 12-Jun-2004 22:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:53.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.