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 > String.h

String.h
Thread Tools
Banned
Join Date: Mar 2000
Location: Sherman Oaks, CA USA
Status: Offline
Reply With Quote
Jul 29, 2002, 05:20 AM
 
Okay, so my C++ book has an assignment in it that requires the library <lvp\string.h> So far, I have learnedd that <lvp\string.h> doesn't exist in any form of that type, but it does live on in string.h. So, I got that put into my assignment, but now, it still can't make out the class String in the beginning of the app. The rest of it is fine.

Anything that has // in front of it is there because when I bring it to class to compile it there, I need those, but for Project Builder, they remain off.

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">/* Vote Analysis program. Names and votes for two candidates are entered and the percentages and votes are displayed in a table.
Chris Hanks 7-29-02 */

#include &lt;iostream.h&gt;
//#include &lt;conio.h&gt;
#include &lt;strings.h&gt;

int main()
{
//clrscr();
cout &lt;&lt; &quot;-- Vote Analysis Program --&quot; &lt;&lt; endl &lt;&lt; endl;

String Candidate1, Candidate2;
cout &lt;&lt; &quot;Enter name of first candidate: &quot;;
cin &gt;&gt; Candidate1;
cout &lt;&lt; &quot;Enter name of second candidate: &quot;;
cin &gt;&gt; Candidate2;

long Votes1, Votes2;
cout &lt;&lt; &quot;Enter votes for &quot; &lt;&lt; Candidate1 &lt;&lt; &quot;: &quot;;
cin &gt;&gt; Votes1;
cout &lt;&lt; &quot;Enter votes for &quot; &lt;&lt; Candidate2 &lt;&lt; &quot;: &quot;;
cin &gt;&gt; Votes2;
cout &lt;&lt; endl;

long VotesTotal = Votes1 + Votes2;
double Percent1 = 100 * double (Votes1)/VotesTotal;
double Percent2 = 100 * double (Votes2)/VotesTotal;

const int ColWidth = 10; // Width of columns in table
cout.setf(ios::fixed);
cout.precision(2);

// Output column headings
cout.setf(ios::left);
cout.width(ColWidth); cout &lt;&lt; &quot;Candidate&quot;;
cout.setf(ios::right);
cout.width(ColWidth); cout &lt;&lt; &quot;Votes&quot;;
cout.width(ColWidth); cout &lt;&lt; &quot;Percent&quot; &lt;&lt; endl;

// Output election results
cout.setf(ios::left);
cout.width(ColWidth); cout &lt;&lt; Candidate1;
cout.setf(ios::right);
cout.width(ColWidth); cout &lt;&lt; Votes1;
cout.width(ColWidth); cout &lt;&lt; Percent1 &lt;&lt; endl;

cout.setf(ios::left);
cout.width(ColWidth); cout &lt;&lt; Candidate2;
cout.setf(ios::right);
cout.width(ColWidth); cout &lt;&lt; Votes2;
cout.width(ColWidth); cout &lt;&lt; Percent2 &lt;&lt; endl;

cout.width(ColWidth); cout &lt;&lt; &quot;TOTAL: &quot;;
cout.width(ColWidth); cout &lt;&lt; VotesTotal &lt;&lt; endl;

return(0);
} </pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">So what class should be used in place of String? Is there another header file out there that can do a better job?

HELP!
     
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status: Offline
Reply With Quote
Jul 29, 2002, 10:41 AM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by The Dude:
<strong>Okay, so my C++ book has an assignment in it that requires the library &lt;lvp\string.h&gt; So far, I have learnedd that &lt;lvp\string.h&gt; doesn't exist in any form of that type, but it does live on in string.h. So, I got that put into my assignment, but now, it still can't make out the class String in the beginning of the app. The rest of it is fine.

Anything that has // in front of it is there because when I bring it to class to compile it there, I need those, but for Project Builder, they remain off.
So what class should be used in place of String? Is there another header file out there that can do a better job?

</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Why don't you write a String Object yourself?
     
Dedicated MacNNer
Join Date: May 2002
Location: The Swamp
Status: Offline
Reply With Quote
Jul 29, 2002, 12:31 PM
 
Hello,

I think your include statement for the string class is incorrect, it should be

#include &lt;string.h&gt;

It sounds to me that you're using a Lawrenceville Press Book, I'm guessing "An Intro to C++"? I think I bought that book a while back when I was taking an AP course. If it is that book, there should be a CD that has those particular classes on it.
12" PB 1 GHz Combo, 60GB, 512MB, AE
40GB iPod
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Jul 29, 2002, 12:52 PM
 
Use #include &lt;string&gt; (without a .h) and the class name is 'string'. The clrscrn thing is not standard C++.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Banned
Join Date: Mar 2000
Location: Sherman Oaks, CA USA
Status: Offline
Reply With Quote
Jul 29, 2002, 01:29 PM
 
Yes, it is Lawrenceville book, "A Guide to Programming in C++" or something along those lines. I didn't get a CD with the book, instead we're using Borland Turbo C++ v3.

I'm entirely aware that clrscr isn't a standard C++ class, that's why I have it turned off. That way, I can bring it back the lab.

Bell rang. Bye.
     
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status: Offline
Reply With Quote
Jul 29, 2002, 03:37 PM
 
The assignment is asking you to use their String class, whereas the '#include &lt;string&gt;' is using the standard C++ string class. This could be a major problem as the interfaces to the classes may differ in important ways. It looks like the String class should come on a CD.

BTW, clrscr() is in 'conio.h' and is a DOS thing, IIRC.
     
Banned
Join Date: Mar 2000
Location: Sherman Oaks, CA USA
Status: Offline
Reply With Quote
Jul 29, 2002, 05:53 PM
 
Gator, smeger, Lord, dude...I like love you guys!!

Works like a charm!!! THANK YOU!!!
     
   
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 11:16 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