Solved

make a string that gets appended to

Posted on 2004-09-19
5
204 Views
Last Modified: 2010-04-01
i would like to make a string output so i can get the length of it to produce a separating line because the Y value comes from a file and if i set it as a const variable it would in instances be too short or too long heres the function i'd like to update.

void printmapstats(ofstream& mstats, int movestats[][100], int maxX, int maxY)
{
mstats << right << setw(50) << "**********************" << endl<< setw(50)
    << "*   Map Statistics   *" << endl << setw(50)
    << "**********************" << endl << endl;
    int j=0, i = 0;
    mstats << setw(39) << "Y" << endl << "  ";

*** this is the one i'd like to make a string to get a length of to setup a for loop.
    mstats << endl << setw(3) << "*" << setw(5) << "*" << setw(4) << i << setw(2)
    << "*";
    for (int i = 1; i < maxY; i++)
    {
       mstats << setw(4) << i << setw(2) << "*";
    }
    mstats << endl << endl;
***

    for (int i=0; i < maxX; i++)
    {
        if (i == (maxX / 2) - 1)
        {
            mstats << "X" << right << setw(2) << "*" << setw(3) << i << " *" ;
        }
        else
        {
            mstats << setw(3) << "*" << setw(3) << i << " *";
        }
        mstats << setw(4) << movestats[i][j] << " |";
        for (j=1; j < maxY; j++)
        {
            mstats << setw(4) << movestats[i][j] << " |";
        }
        mstats << endl << endl;
    }
}

as of now it prints out:

  *    *   0 *   1 *   2 *   3 *   4 *   5 *   6 *   7 *   8 *   9 *  10 *  11 *

  *  0 *   0 |   1 |   3 |   4 |   7 |   5 |   4 |   3 |   2 |   2 |   1 |   0 |

my desired output would be something like:

  *    *   0 *   1 *   2 *   3 *   4 *   5 *   6 *   7 *   8 *   9 *  10 *  11 *
*****----------------------------------------------------------------------
  *  0 *   0 |   1 |   3 |   4 |   7 |   5 |   4 |   3 |   2 |   2 |   1 |   0 |

Any Ideas?
0
Comment
Question by:marineknight22
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 20 total points
ID: 12148838
Don't have to make a string to calculate, just do this:

int len=0;   // create this variable
*** this is the one i'd like to make a string to get a length of to setup a for loop.
    mstats << endl << setw(3) << "*" << setw(5) << "*" << setw(4) << i << setw(2)
    << "*";
    for (int i = 1; i < maxY; i++)
    {
       mstats << setw(4) << i << setw(2) << "*";
       len += 6;   // accumulate length here
    }
    mstats << endl << endl;
***

    string line(len, '-');   // create string here
    mstats << "*****" << line << endl;    // display it
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12599975
I think my answer is correct but have to hear to author.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ to C# code conversion issue 4 112
sorting efficency of sorting algorithm 30 121
How can i compile this github project?? 2 91
Android development question 2 54
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question