Jump to content
  • Advertisement
Sign in to follow this  
zell901

confused with "string"

This topic is 3886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well, first off I'm following a book that might be pretty old, so explain how I should correct anything thats out of date please, but the main problem I'm having is "apstring.h" the book says it just introduces a string, is there another #include file I can use to allow strings? (sorry im not sure what to enclose this in to get the code thing) #include <iostream> #include <conio.h> #include "apstring.h" int main() { apstring Name1 = "Suzie"; apstring Name2 = "Seymour"; clrscr(); std::cout << "Name1 = " << Name1 << std::endl; std::cout << "Name2 = " << Name2 << std::endl; getch(); return 0; } the error i get says cannot get the #include file "apstring.h"

Share this post


Link to post
Share on other sites
Advertisement
Yes. First, trash your book. If you were doing the AP exam, it's in Java now. So it wouldn't help anyway. And if you truly wanted to learn modern C++, the book is useless anyway. Get a significantly better one like C++ Primer by Lippman and Accelerated C++ by Koenig.

There is a C++ string class, a good, standardised one. Look up C++ string on Google. Just type in "C++ string" on google. Google, aside from finding you answers to question like why the sky is blue, will also answer your programming questions ;p.

Oh, and don't rely on conio.h . Please, don't ever.

Share this post


Link to post
Share on other sites
Just so you're clear as to what's going wrong with your program...when you specify a file to be included via the #include directive, your compiler needs to be able to find this file. Usually this is done one of two ways:

-Having the file in the same folder as the rest of your source code files
-Telling the compiler a directory where it should look for header filers

Now apstring.h, being a header file that was formerly produced and distributed by the college board for AP exams, is not a file that comes standard with any compilers. This means you would have to find it and download it, and then make sure the compiler can access it through one of the two methods mentioned above.

However I advise that you simply stick with the string class found in the C++ Standard Library. You'll be able to access it with any C++ compiler, and it's just as full-featured as the apstring class.

Share this post


Link to post
Share on other sites
yes, you need to #include <string>
Like this:


#include <iostream>
#include <string>

int main()
{
std::string word;
std::cin >> word;
std::cout << "You have entered " << word << std::endl;

return 0;
}

Share this post


Link to post
Share on other sites
Instead of getch() use std::cin.get().
I can't replace clrscr() because there is no standard way to clear the console window in C++, as such I would recommend just not even bothering.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!