473,480 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

fprintf format


Hi

I am trying to pretty print to file 3 vectors (int,double,double)
where all the cells match like a table format where every thing lines
up to the left and space padded to the right.
does c++ has something or mostly use C fprintf?

1255251 0.251025 215.2541
thats how I like it to look, where the space is to the right of the
number and the number left aligns with the field border.

here is my patented effort

int main() {
sync_with_stdio(); //to mix C and C++

ofstream out("output.txt")
for (int i=0; i<vect.size(); i++){
fprintf(out,
"%d8 %f8 %f8"
,vect1[i], vect2[i], vect3[i])
}}

thanks for helping

Aug 4 '06 #1
5 4089
Gary Wessle wrote:
I am trying to pretty print to file 3 vectors (int,double,double)
where all the cells match like a table format where every thing lines
up to the left and space padded to the right.
does c++ has something or mostly use C fprintf?

1255251 0.251025 215.2541
thats how I like it to look, where the space is to the right of the
number and the number left aligns with the field border.

here is my patented effort

int main() {
sync_with_stdio(); //to mix C and C++

ofstream out("output.txt")
for (int i=0; i<vect.size(); i++){
fprintf(out,
"%d8 %f8 %f8"
Any width you need should be placed between the % sign and the format
specifier ('d' or 'f'): %8d %8f. RTFM, please.
,vect1[i], vect2[i], vect3[i])
}}

thanks for helping
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 4 '06 #2
"Victor Bazarov" <v.********@comAcast.netwrites:
Gary Wessle wrote:
I am trying to pretty print to file 3 vectors (int,double,double)
where all the cells match like a table format where every thing lines
up to the left and space padded to the right.
does c++ has something or mostly use C fprintf?

1255251 0.251025 215.2541
thats how I like it to look, where the space is to the right of the
number and the number left aligns with the field border.

here is my patented effort

int main() {
sync_with_stdio(); //to mix C and C++

ofstream out("output.txt")
for (int i=0; i<vect.size(); i++){
fprintf(out,
"%d8 %f8 %f8"

Any width you need should be placed between the % sign and the format
specifier ('d' or 'f'): %8d %8f. RTFM, please.
,vect1[i], vect2[i], vect3[i])
}}

thanks for helping

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
after all kind of trial and error, I wish I could find some
step-by-step gentle into to the fprintf with lots of examples for
the dummy.

but here it is for the records, in c++ and not c

************************************************** **************
#include "boost/format.hpp"
using boost::format;

ofstream out("output.txt");
format fmter("%1% %12t%2% %25t%3%\n");//very close to fprintf format

for(unsigned i=0; i<vect1.size(); i++){
fmter % vect1[i];
fmter % vect2[i];
fmter % vect3[i];
exp << fmter.str();
}

I came to this after reading as much as I can understand from the
manual.
Aug 4 '06 #3
Gary Wessle <ph****@yahoo.comwrote:
I am trying to pretty print to file 3 vectors (int,double,double)
where all the cells match like a table format where every thing lines
up to the left and space padded to the right.
does c++ has something or mostly use C fprintf?

1255251 0.251025 215.2541
thats how I like it to look, where the space is to the right of the
number and the number left aligns with the field border.

here is my patented effort

int main() {
sync_with_stdio(); //to mix C and C++

ofstream out("output.txt")
for (int i=0; i<vect.size(); i++){
fprintf(out,
"%d8 %f8 %f8"
,vect1[i], vect2[i], vect3[i])
}}
Look into using the facilities provided by the <iomanipheader.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Aug 4 '06 #4
Gary Wessle wrote:
after all kind of trial and error, I wish I could find some
step-by-step gentle into to the fprintf with lots of examples for
the dummy.

but here it is for the records, in c++ and not c

************************************************** **************
#include "boost/format.hpp"
using boost::format;

ofstream out("output.txt");
format fmter("%1% %12t%2% %25t%3%\n");//very close to fprintf format

for(unsigned i=0; i<vect1.size(); i++){
fmter % vect1[i];
fmter % vect2[i];
fmter % vect3[i];
exp << fmter.str();
}

I came to this after reading as much as I can understand from the
manual.
Why not use std::cout instead? It's standard (unlike Boost), type-safe,
and is preferred in C++ land. Consult your C++ reference (if you don't
have one, get one recommended at accu.org) on how to use the items in
the iomanip header to achieve the same effect in a more idiomatic C++
way.

Cheers! --M

Aug 4 '06 #5
Gary Wessle <ph****@yahoo.comwrites:
"Victor Bazarov" <v.********@comAcast.netwrites:
Gary Wessle wrote:
I am trying to pretty print to file 3 vectors (int,double,double)
where all the cells match like a table format where every thing lines
up to the left and space padded to the right.
does c++ has something or mostly use C fprintf?
>
1255251 0.251025 215.2541
thats how I like it to look, where the space is to the right of the
number and the number left aligns with the field border.
>
here is my patented effort
>
int main() {
sync_with_stdio(); //to mix C and C++
>
ofstream out("output.txt")
for (int i=0; i<vect.size(); i++){
fprintf(out,
"%d8 %f8 %f8"
Any width you need should be placed between the % sign and the format
specifier ('d' or 'f'): %8d %8f. RTFM, please.
,vect1[i], vect2[i], vect3[i])
}}
>
thanks for helping
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

after all kind of trial and error, I wish I could find some
step-by-step gentle into to the fprintf with lots of examples for
the dummy.

but here it is for the records, in c++ and not c

************************************************** **************
#include "boost/format.hpp"
using boost::format;

ofstream out("output.txt");
format fmter("%1% %12t%2% %25t%3%\n");//very close to fprintf format

for(unsigned i=0; i<vect1.size(); i++){
fmter % vect1[i];
fmter % vect2[i];
fmter % vect3[i];
exp << fmter.str();
}

I came to this after reading as much as I can understand from the
manual.
correction
the last line of the above code should be
out << fmter.str();
Aug 4 '06 #6

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

Similar topics

2
1604
by: joy_julia446 | last post by:
Hi there, I tried to write to an output file like: Hello USER_NAME You are visitor no:COUNT USER_NAME : string and can be of any length bt 1 and 30. You: The char 'Y' has fixed...
6
3473
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being...
3
3139
by: Andrew Fabbro | last post by:
I have code with stuff like this all over it: sprintf(errmsg,"somefunc(): %s has illegal character %c",somestring,somechar); fatal_error(errmsg); where fatal_error() just fprintf's to stderr...
6
2980
by: Magix | last post by:
Hi, I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s...
9
3873
by: Harry | last post by:
Good Day, Is there a way to print 8 bytes in a line in a file using fprintf...like this 12 76 89 76 86 34 98 08 A4..............................
4
2702
by: grimrob | last post by:
fprintf just is not working. I am using PHP Version 4.3.9. Whatever I do fprintf just fails. For example: fwrite($Handle, 'A1'); fprintf($Handle, 'A2); The first line always works, the...
16
6658
by: Prayag Narula | last post by:
Hi, I want to redefine fprintf for debugging purposes. That is I want that all the output that is going to the stdout should be logged in a file. I tried something like #define fprintf...
11
4256
by: David Mathog | last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix write, but no fwrite. That is, no portable C method for writing binary data, only system calls which were OS specific. At...
4
8056
by: spiralfire | last post by:
I wrote a translator, that reads a DIMACS graph format and writes to a simpler format... basically DIMACS format is: c comment p type nodes edges //type is alwats edge on my problems,...
0
7054
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7057
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
7102
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
5357
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,...
0
4495
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...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3000
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1310
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.