2

I need to get code work in Turbo C++. But the data type string does not work; using namespace std gives Compiler Error and I can't use string without it. Even std::string does not work.

It works perfectly fine in Code::Blocks but I want it to work in Turbo C++. I know Turbo is a very old compiler and I should be using the new ones. But it is a college project which has to be done in Turbo C++. Are there any ways to make it work in Turbo C++?

14
  • 15
    Turbo C++ is old, ancient really. Most importantly it is from before C++ was standardized, and so doesn't have the standard headers or the standard namespace. If you need to use Turbo C++ then you need to learn the pre-standard classes and headers. Your best chance is to pick up an old book, from the early to mid 1990's. And then you have to live with the knowledge that much of what you learn won't really be useful in the future, it will be a waste of time. Nov 3, 2016 at 10:09
  • i know i have to do this work for some one who wants it done in turbo c++
    – user49557
    Nov 3, 2016 at 10:12
  • 7
    The someone that's telling you it must be done in Turbo C++ should be shot. Nov 3, 2016 at 10:18
  • 3
    Your college is ripping you off. Complain. Besides, most users here probably were in preschool when TC++ fell out of fashion, and so may not be terribly familiar with it.
    – n. m.
    Nov 3, 2016 at 10:21
  • 3
    One thing to keep in mind: The C++ of Turbo C era is basically a different language, than what C++ is today. So think of them that way. Sure, they have a lot of similarities, old one is mostly a (small) subset of current one, with a few differences, but modern "recommended" C++ style and best practices and so on are completely, totally different.
    – hyde
    Nov 3, 2016 at 10:35

6 Answers 6

4

This kind of depends on which version of Turbo C++ you have. Some software archeology:

Ancient DOS versions up to 3.1 didn't support STL well, nor did they support #include <string>. They used the pre-standard include formats with .h extensions: #include <string.h> etc. Try to add a .h and you might get lucky.

Somewhere around version 4 or 5.0 they started to support #include <string> header formats and most of STL. These were still pre-standard compilers.

STL support remained questionable in earlier versions of Borland Builder, until somewhere around Builder 5. That should be version 5.5 or so of the BCC compiler.

The RAD tool called Turbo C++, released somewhere around 2005, should have full support for C++98.

2

Turbo C++ doesn't support namespaces.

I think you need to include cstring.h and not use any namespaces or even the using directive.

#include <cstring.h>

And I don't think it supports templates either.

3
  • cstring serves for null-terminated strings (aka C-strings), not std::string. OP might have to rewrite the whole code to use C-strings instead of std::string.
    – Melebius
    Nov 3, 2016 at 10:43
  • 2
    @Melebius - cstring.h, not cstring.
    – user93353
    Nov 3, 2016 at 10:44
  • I'm pretty sure it was string.h. cstring.h will not give you std::string.
    – Lundin
    Nov 3, 2016 at 11:59
2

There is absolutely no way whatsoever to make modern C++ code work in Turbo C++ as is. Lots of it needs to be rewritten.

There is nothing std:: in turbo c++. There are no namesoaces. There are no templates. There is very little of what we know as the standard library. Basically you have to unlearn most of what you know about C++. Classes and functiins mostly do work. Iostreams may somewhat work if you #include <iostreams.h> (note the .h) and omit std::. Otherwise you are pretty much confined to the C standard library.

If you need a string class, you probably will have to make your own.

Tread carefully, read the built-in help, examine the included example programs, and you might be able to pull it off.

Note, later versions of the product (not called Turbo C++ IIRC, but rather Borland C++ or Borland Builder) have improved support for C++98, including the standard library.

0

I had the same problem then I realized that I had forgotten using namespace std That solved everything.

-1

In place of String you can use the character array. For example, we need to declare the variable str as a string. It can be done simply as:

char a[10]; // the 10 is the size of the array.

A seperate header file is included to use the library functions.

-1

Okay, after a lot of hassle, I found the way. Unfortunately, you can't use string and other such data types as they were not even implemented at that time. You need to do what used to be done before. Use char array instead of string and create functions related to that.

Now char array has a lot of limitations and problems, that's the reason string was implemented. But you have to write char array functions the same way string was written from scratch.
If you want to compare or copy two char arrays, you have to loop and compare them. It will be little complicated, but that's the best way which worked for me.

I can give some sample code for a certain task if needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.