473,395 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

write to output file Query

Hi there,
I would like to print my result as below in an output file. I would
appreciate if someone can give me some advice.

RESULT
ClassA,96.678,88.196,8.048,-0.233,456.231,5.890, 1
11.371,-0.906,-0.025,9999.888,76.888,0.001,3456.899 2
20.422,-20.979,0.422,4567.987,987.987,0.985,0.445, 3
-0.044,0.905,1.335,890.987,34.567,32.235,76.874; 4
let say the results are stored in an arry:
a[0] = 96.678, a[1] = 88.196, a[2] = 8.048, a[3] = -0.233, a[4] =
11.371, a[5] = -0.906, .........a[26] = 76.874.

The max column for each line that I can print is 51. Once it reach 51,
I need to start the next row.

The figure on the far right side ie. 1 2 3 and 4 represents the row
number and have to be printed at column 54th.

My query:
1.How am I suppose to keep track the number of row that I have printed?
for example, I have used 48columns in row1. Since 11.371 occupies
6spaces, I need to start the new line.

2. How do fix the row number at column 54th?

Please kindly note that the size of the array can be as large as
thousand. In this case, I try to simplify my problem here.

Thank you

Sep 6 '05 #1
1 1474
<jo**********@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi there,
I would like to print my result as below in an output file. I would
appreciate if someone can give me some advice.

RESULT
ClassA,96.678,88.196,8.048,-0.233,456.231,5.890, 1
11.371,-0.906,-0.025,9999.888,76.888,0.001,3456.899 2
20.422,-20.979,0.422,4567.987,987.987,0.985,0.445, 3
-0.044,0.905,1.335,890.987,34.567,32.235,76.874; 4
let say the results are stored in an arry:
a[0] = 96.678, a[1] = 88.196, a[2] = 8.048, a[3] = -0.233, a[4] =
11.371, a[5] = -0.906, .........a[26] = 76.874.

The max column for each line that I can print is 51. Once it reach 51,
I need to start the next row.

The figure on the far right side ie. 1 2 3 and 4 represents the row
number and have to be printed at column 54th.

My query:
1.How am I suppose to keep track the number of row that I have printed?
for example, I have used 48columns in row1. Since 11.371 occupies
6spaces, I need to start the new line.
Keep the current line in std::string format and check whether the new part's
addition will wrap the line. A templatized member function should work fine:
class Line
{
/* ... */

// The constructor can take the actual output stream and the line length.
// You could also get the delimiter here...
Line(ostream & output, size_t line_length);

template <class T>
void add(T const & object)
{
string const new_part = as_string(object);

if (line_.size() + new_part.size() + 1 > line_length_)
{
/* TODO: output the current line here */

line_ = new_part;
}
else
{
line_ += " ";
line_ += new_part;
}
}
};

You can use boost::lexical_cast, or this poor function for as_string:

// Prefer boost::lexical_cast to this crippled function
template <class T>
string as_string(T const & object)
{
ostringstream stream;
stream << object;
return stream.str();
}

You could then use Line as:

Line line(cout, 51);

line.add("ClassA");
line.add(96.678);


2. How do fix the row number at column 54th?


Look at setw manipulator that is defined in <iomanip>. Basically you would
set the width of the line number, before outputting it:

your_output_stream << setw(4) << line_number_;

Ali

Sep 6 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joe Gazda | last post by:
I'm a relative newbie to PHP, but have been able to put together some PHP code to generate a CSV/XLS file from a Query result. Now, I would like to include custom column names instead of the MySQL...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
2
by: jeff_zhang446 | last post by:
Hi, I try to write some data structure into a file as below and would appreciate if someone can give me some advice here. The output file looks like below: row(1) 100 1 0 0 0 0 0 0 0 ...
14
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure...
4
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last...
0
gauravgmbhr
by: gauravgmbhr | last post by:
Hi All, I am using a application that stores a scripts in a sql server table columns some times i require to use the scripts stored in table columns in a file. So i am lookin for a keyword...
4
by: myth0s | last post by:
(After thinking about it, maybe this should have been posted in the .NET forum...) Hi, I have a stored procedure in SQL Server that sends me a 3000+ char pre-formatted XML string. I use "FOR...
3
by: Bre-x | last post by:
I would like to output a odbc query to a text file. I have the following php code but it isnt working. <? //conneccion $conn=odbc_connect('DBA','',''); if (!$conn) {exit("Connection...
5
by: Jon Skeet [C# MVP] | last post by:
On Sep 9, 9:41 am, raylopez99 <raylope...@yahoo.comwrote: It's tricky in .NET for two reasons: 1) LINQ doesn't have any concept of "remove" 2) List<T>.RemoveAll doesn't pass in the index...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.