473,626 Members | 3,675 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

much text, one cout<< ?

Is this going to cause me a portability problem?
Purpose: make it easy for me to write my 'help' text block in the .cpp file,
just as I wish it to be output 'formatted-ly' to the user upon demand while
the program is running.

#include <iostream>;
using namespace std;

int main() {
cout<<"these \
lines\n\
are \
much \
longer\n\
than \
this.\n";

return 0;
}

(Or, any better suggestion, without more code?)
Thanks
--
Peace
JB
jb@tetrahedrave rse.com
Web: http://tetrahedraverse.com

Feb 9 '08 #1
12 1972
John Brawley wrote:
Is this going to cause me a portability problem?
It's not valid C++, so, yes, you bet.
Purpose: make it easy for me to write my 'help' text block in the
.cpp file, just as I wish it to be output 'formatted-ly' to the user
upon demand while the program is running.

#include <iostream>;
using namespace std;

int main() {
cout<<"these \
lines\n\
are \
much \
longer\n\
than \
this.\n";

return 0;
}

(Or, any better suggestion, without more code?)
Thanks
Surround every line of text with double quotes.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 9 '08 #2
On 2008-02-09 19:15, John Brawley wrote:
Is this going to cause me a portability problem?
Purpose: make it easy for me to write my 'help' text block in the .cpp file,
just as I wish it to be output 'formatted-ly' to the user upon demand while
the program is running.

#include <iostream>;
using namespace std;

int main() {
cout<<"these \
lines\n\
are \
much \
longer\n\
than \
this.\n";

return 0;
}

(Or, any better suggestion, without more code?)
If you have a number of string literals after each other they will be
concatenated when compiling, just write each line enclosed by double quotes:

#include <iostream>

int main()
{
std::cout <<
"Here begins a number "
"of long lines";
}
Do not forget adding newlines (\n) wherever you need one.

--
Erik Wikström
Feb 9 '08 #3
On Feb 9, 8:32 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
John Brawley wrote:
Is this going to cause me a portability problem?
It's not valid C++, so, yes, you bet.
What's wrong with it? It's not good C++, but it looks legal to
me.
Purpose: make it easy for me to write my 'help' text block
in the .cpp file, just as I wish it to be output
'formatted-ly' to the user upon demand while the program is
running.
#include <iostream>;
using namespace std;
int main() {
cout<<"these \
lines\n\
are \
much \
longer\n\
than \
this.\n";
return 0;
}
(Or, any better suggestion, without more code?)
Surround every line of text with double quotes.
Which will make the code more readable (since the following
lines can be correctly indented), but won't change anything in
the meaning of the code.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 9 '08 #4
On Feb 9, 7:15 pm, "John Brawley" <jgbraw...@char ter.netwrote:
Is this going to cause me a portability problem?
Purpose: make it easy for me to write my 'help' text block in the .cpp file,
just as I wish it to be output 'formatted-ly' to the user upon demand while
the program is running.
#include <iostream>;
using namespace std;

int main() {
cout<<"these \
lines\n\
are \
much \
longer\n\
than \
this.\n";
return 0;
}
(Or, any better suggestion, without more code?)
In general (or at least in theory), every program has a
potential portability problem. All implementations have
ressource limits, and if you exceed them, you're going to get
into trouble. As long as your string doesn't exceed the maximum
string length of the compiler, however, and there's enough room
for it in the memory in which the program runs, this should not
cause a problem.

To tell the truth, I have no idea what the maximum string length
for a compiler might be, but I have, on occasion, had strings
which represented tens of lines of output---several KB in
all---, without the slightest problem. (One would hope, of
course, that the maximum string length would only be limited by
the memory available to the compiler, but one never knows.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Feb 9 '08 #5

"John Brawley" <jg*******@char ter.netwrote in message
news:1b******** *****@newsfe06. lga...
Is this going to cause me a portability problem?
Purpose: make it easy for me to write my 'help' text block
in the .cpp file, just as I wish it to be output 'formatted-ly' to
the user upon demand while the program is running.

#include <iostream>;
using namespace std;

int main() {
cout<<"these \
lines\n\
are \
much \
longer\n\
than \
this.\n";

return 0;
}
Thanks Victor, James, Erik, Kai-Uwe;
I deduce:
Mine is legal (it works, no serious portability problem), but poor C++
practice. (Even though the console window of help text looks exactly like I
want it to.)
I'll think about it more but probably take your suggestions and use
doub-quotes around every line. It'll be 'uglier' to me in the .cpp file,
but
I'd just as soon do things "the right way" whenever possible.
Appreciated.
(It was unexpectedly interesting to see the first two kind helpers
disagreeing with each other... (*grin*) ...over what I feared was 'way too
simple (newbie-ignorant) a question for an actual disagreement from
experienced programmers to arise.)
Have a nice day!

--
Peace
JB
jb@tetrahedrave rse.com
Web: http://tetrahedraverse.com

Feb 10 '08 #6

Oops sorry missed the \ at the end of the line.
Feb 11 '08 #7
Martin York wrote:
Oops sorry missed the \ at the end of the line.
And the context!

--
Ian Collins.
Feb 11 '08 #8
I'll think about it more but probably take your suggestions and use
doub-quotes around every line. It'll be 'uglier' to me in the .cpp file,
but
I'd just as soon do things "the right way" whenever possible.
Appreciated.
This is a perfect example of a place where you can separate data and
code.
You don't really want the text in the source. If you move the data out
of the code into a separate file you increase readability (as it is
not ugly) you increase portability (as you can then localize the
string without changing the code (a bit of extra work required but not
much)) you reduce your probability of running into compiler specific
limits.

Personally I would do somthing like this:

1) Put the text in a seprate file:

std::ifstream text(getLocalis edFileName());
std::copy(std:: istreambuf_iter ator<char>(text ),std::istreamb uf_iterator<cha r>(),std::ostre am_iterator<cha r>(std::cout)) ;
Feb 11 '08 #9
On Feb 10, 5:17 pm, "John Brawley" <jgbraw...@char ter.netwrote:
"John Brawley" <jgbraw...@char ter.netwrote in message
[...]
I'll think about it more but probably take your suggestions
and use doub-quotes around every line. It'll be 'uglier' to
me in the .cpp file, but I'd just as soon do things "the right
way" whenever possible.
I'm curious. Why uglier? Your solution doesn't allow
indentation of any but the first line---using separate string
literals (concatenated by the compiler) does.

Of course, if this is really a more or less large body of text
that you want to maintain as text, the best solution is to do
just that---maintain it as text, in a separate file. If you
still want to have it "compiled into" your program (there are
pros and contras to this), then a simple preprocessor will
convert it to a C style array. Something like:

#! /usr/bin/awk
BEGIN {
print "// Automatically generated file"
print "// DO NOT EDIT"
print ""
print "#include \"helpText.hh\" "
print ""
print "char const helpText[] ="
}
{
print " \"" $0 "\""
}
END {
print ";"
}

Then create (manually) the necessary "helpText.h h" header (which
is just one line), and the work is done.

(FWIW: I'd strongly recommend this. Maintaining text in a
format that has a C++ string literal per line will be a pain,
e.g. anytime one line gets to long, and you have to reformat the
paragraph. Whereas if the file is pure text, and the editor
recognizes it as such, it will do the reformatting for you.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Feb 11 '08 #10

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

Similar topics

7
9018
by: Ensoul Chee | last post by:
I used #include <iostream.h> int m; cout << "Hexadecimal == 0x" << hex << m << endl; to print value of m in hexadecimal mode. But I got the compile error like this couttest.cpp:20 `hex' undeclared (first use this function)
4
5795
by: karolina | last post by:
Hi I am playing around with visual studio 7.0. Why does the code below do like it does? Where do I set the character set to use in cout, properties->configuration properties->General->character does not do the trick. #include <iostream> using namespace std;
4
2053
by: bluekite2000 | last post by:
Here A is an instantiation of class Matrix. This means whenever user writes Matrix<float> A=rand<float>(3,2);//create a float matrix of size 3x2 //and fills it up w/ random value cout<<A; the following will be printed A 3 2
4
1749
by: wangzhihuii | last post by:
Hi all, I'm really confused, can cout<<""; contribute anything to the routine ?!! my programm won't work properly without this trivial sentence. Sincerely vivian
12
6086
by: Filipe Sousa | last post by:
Hi! Could someone explain to me why this operation is not what I was expecting? int main() { int x = 2; std::cout << x << " " << x++ << std::endl; return 0; }
46
3378
by: suresh | last post by:
Hi, For this code snippet, I get the following output, which I am unable to understand. (2^31 = 2147483648) cout<< -2147483648 << endl; cout << numeric_limits<int>::min() <<',' << numeric_limits<int>::max()<< endl;
42
4516
by: barcaroller | last post by:
In the boost::program_options tutorial, the author included the following code: cout << "Input files are: " << vm.as< vector<string() << "\n"; Basically, he is trying to print a vector of string, in one line. I could
0
8265
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8705
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
8637
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
8364
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,...
0
4092
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
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 we have to send another system
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
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.