I'm trying to find a easier way to add space between the Client and the Business type i tried using setw() in the array and in the first cout i had no luck. How can i add space between the strings and keep them in their columns instead of spacing out the array like i did in this program. I gotthis program format fromthis site.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
void bubbleSort(string[], int);
int main ()
{
int y = 0;
string Client[12] = { "Acme Construction Machinery design", "Johnson Electrical Switch manufacturing", "Brown Heating and Cooling Boiler design", "Smith Switches Switch manufacturing", "Jones Computers Computers sales",
"Williams Cleaning Equipment Machinery sales" };
cout << "Clients"<< " Business types" << endl;
for (int i=0; i<12; i++)
cout << Client[i] << endl;
return 0;
}
void bubbleSort(string arr[], int n)
{
bool swapped = true;
int j = 0;
string tmp;
while (swapped)
{
swapped = false;
j++;
for (int i = 0; i < n - j; i++)
{
if ( arr[i].compare(arr[i - 1]) )
{
tmp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = tmp;
swapped = true;
}
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1
1>Deleting intermediate and output files for project 'WeekSixProgram', configuration 'Debug|Win32'
1>Compiling...
1>WeekSixProgram.cpp
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
1>LINK : C:\Users\Martin\Documents\Visual Studio 2008\Projects\WeekSixProgram\Debug\WeekSixProgram.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Build log was saved at "file://c:\Users\Martin\Documents\Visual Studio 2008\Projects\WeekSixProgram\WeekSixProgram\Debug\BuildLog.htm"
1>WeekSixProgram - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
I don't see how setw is going to help you with that problem if you wish for the client and business type to be part of the same string. You should use \t characters (tabs) by inserting \t instead of spaces between the strings.