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 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
"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.
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
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
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(); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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..............................
| |
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...
|
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...
|
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...
|
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,...
|
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,...
|
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,...
| |
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...
|
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: 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |