473,769 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,8 8.196,8.048,-0.233,456.231,5 .890, 1
11.371,-0.906,-0.025,9999.888, 76.888,0.001,34 56.899 2
20.422,-20.979,0.422,45 67.987,987.987, 0.985,0.445, 3
-0.044,0.905,1.3 35,890.987,34.5 67,32.235,76.87 4; 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 1508
<jo**********@y ahoo.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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,8 8.196,8.048,-0.233,456.231,5 .890, 1
11.371,-0.906,-0.025,9999.888, 76.888,0.001,34 56.899 2
20.422,-20.979,0.422,45 67.987,987.987, 0.985,0.445, 3
-0.044,0.905,1.3 35,890.987,34.5 67,32.235,76.87 4; 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(objec t);

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("Class A");
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_str eam << 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
3919
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 column table names. I know that there are codes to generate tabs and carriage returns, but can't find anything about including "commas" in a string to output to the file to separate the custom field names. I'd appreciate some help with a line of...
6
4622
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 console as well as to file, my code is as below, ======================================================================= #include <iostream.h> #include<ostream> #include<sstream>
2
2088
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 1 row(2) 150 5 0 0 0 0 0 0 0 2 row(3) 160 7 0 0 0 0 0 0 0 3
14
2682
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 if it is apache, or php, or just an error I am not seeing. here is the code: <?php /** * Loop through the resultset
4
2759
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 time i ask for an entire code or u can give me the outine of what to do and i ll do it by myself. the description is the following: the program will read a text file that contains historical price of a stock. The program will allow users to query...
0
1422
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 like UNLOAD(DB2) which unload the table into a text file. IN short i am looking to write the output of an sql query into an text file. i can't use any utility or anr dos command to do so. can it be done on just query level? Regards,
4
5304
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 XML EXPLICIT" and it works really well when I do the query in Management Studio. But, when it comes to output, something goes wrong. My output code is very basic, I don't know if it could be better. I use ExecuteScalar since the procedure returns...
3
2718
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 Failed: " . $conn);}
5
3674
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 (which makes sense as it would then need to If List<Tsupported some sort of "view" which also exposed RemoveAll, it would be easy:
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.