[cs13001] Lab 7 Issue

Mikhail Nesterenko mikhail at cs.kent.edu
Thu Feb 28 17:06:12 EST 2013


> 
> where s2 is the sum of the strings in the line on the left
> and38 is the number of characters from the beginning of the left side, to
> the right side in the example:
> 
> William Schmidt                       2/23/2010
> 
> Is there an easier why that my brain isn't finding?

For each check line, create a string and collect the output
there. Then, you can use append() or insert() functions to add the
necessary number of spaces. Note that both functions have variants that
accept the number of spaces to be added. For example:

 myString.append(20, ' ');


> 
> Also, I put my old code for number spell into a function. It is currently
> function type void. However, in order to get the length of what it outputs
> for the last line of the check (i.e. cout << "thirteen", "forty six", etc),
> I was trying to change the function type to string so I could use it in
> expressions, and I was having a LOT of trouble. Maybe I'm missing a include
> directive? I can't figure out how to get it to work.
> 
> Let me know if you can help?

This is a curious error that has to do with scopes that we have not
studied yet. Notice how you have to put 

  using namespace std;

In your cpp files. This is necessary so that you can use names defined
elsewhere. "string" is one such name. In the header file, "string" is
unknown which gives you errors. To make this problem go away, you can
put the above statement in your header file. However, it is considered
extremely bad style. We'll deal with it later in the
course. To properly fix the error, precede all your mentions of
"string" with the following statement:

   using std::string;


Thanks,
--
Mikhail


More information about the cs13001 mailing list