Console output?

Started by
12 comments, last by Dublin 20 years, 9 months ago
Hey there, thanks for looking at my post. I have a always compiled my code on a UNIX based system; however, I am trying to make a conversion over to "Visual C++ ver.6 SP5" and eventually to "Visual .NET" so I can program in Windows and write some games. I have been very surprised at the lack of portability of much of my old "UNIX" code. Therefore, I have a 2 part question: 1) I cannot get the following code to work in a console.

/* This is just psudeo-code */
#include <iostream>
#include <iomanip>

cout.width(80);
cout.fill('*');
2. Why does iostream.h and iomanip.h create so many errors as opposed to the same declarations w/o the ".h" "poor is the pupil who does not surpass his master" - leonardo da vinci
"poor is the pupil who does not surpass his master"- leonardo da vinci
Advertisement
Did you remember to include the namespace std?

Something like this:

using namespace std; 


or try to add the binary res operator to your cout like so

std::cout.width(80);std::cout.fill(''*''); 





You fight like a dairy farmer.

--{You fight like a dairy farmer!}

Thanks Greatwolf for your reply.

Yes, I included:

using namespace std;


No, I did not use:

std::cout.width(80);
std::cout.fill('*');


But I am about too.


Later that day in the batcave: Nope using std:: didn't work either.

[edited by - Dublin on July 8, 2003 1:43:58 AM]
"poor is the pupil who does not surpass his master"- leonardo da vinci
My bad!! Kinda?

ok the code works either way with or w/o the "std::".

But only in the main. It doesn''t work in a subfuction that I created. Here is the prototype:

void printHeading(bool aBool, int anInt);

Any Ideas?
"poor is the pupil who does not surpass his master"- leonardo da vinci
I can''t see any reason why it wouldn''t work. It works fine for me but then again I''m using Borland''s compiler, not VC++




You fight like a dairy farmer.

--{You fight like a dairy farmer!}

You sould not really use ''using namespace std;''

it might fuck up things for you if you have many files..

However, using std::cout; should be better..

Put that in all files that uses the cout object..

OR:

skip the using line and put std::cout. Do NOT mix them!!

btw, please post the error msg you''re getting
----------------------------------------------Petter Nordlander"There are only 10 kinds of people in the world. They who understand binary and those who do not"
Perhaps this should be another post, but I''ve been wondering, and since I saw it mentioned in this post, I had to ask. In school and stuff, I was always taught to use "#include <iostream>" and "using namespace std". Once I started looking at game programming code I see a lot of people using std::cout. PhiberOptic, you say use the latter (std::cout), and your reason is because it would mess up things if there are too many files. Could you, or someone, elaborate? Because ever since i started seeing it, I wondered why it''s used. using namespace seems so much easier. I also don''t look forward to having to change my old code, and break my habits....

old coding habits die hard
uhm..
using std::cout;


.lick
Sorry, I had to go to bed last night, to many beers and to much work; therefore, I wasn't thinking straight. So I thought... Then I get home and I come to find the solution to my post. Low and behold, I didn't find anything concret. So if any of you guys out there would be kind enough to pull yourselves away from your on projects to see if you can debug my code, I would GREATLY appreciate it.

The following code compiles error FREE using my compiler "Visual C++ ver. 6 ServicePack 5". However the "print function" does NOT work.
#include <windows.h>#include <iomanip>#include <iostream>#include <sstream>#include <time.h>#include <string>#include <vector>using namespace std;void aPrintFunction();int main(void){		std::cout.width(80);	std::cout.fill('*');	std::cout << "Before aPrintFunction" << endl;	aPrintFunction();		std::cout << "After aPrintFunction" << endl;	std::cout.width(80);	std::cout.fill('*');	return EXIT_SUCCESS;}


Neither does this.

void aPrintFunction(){	std::cout << endl;	std::cout.width(80);	std::cout.fill('*');}   #include <windows.h>#include <iomanip>#include <iostream>#include <sstream>#include <time.h>#include <string>#include <vector>//using namespace std;void aPrintFunction();int main(void){		std::cout.width(80);	std::cout.fill('*');	std::cout << "Before aPrintFunction\n";	aPrintFunction();		std::cout << "After aPrintFunction\n";	std::cout.width(80);	std::cout.fill('*');	return EXIT_SUCCESS;}void aPrintFunction(){	std::cout << "\n";	std::cout.width(80);	std::cout.fill('*');}


[edited by - Dublin on July 8, 2003 9:29:24 PM]

[edited by - Dublin on July 8, 2003 9:34:45 PM]

[edited by - Dublin on July 8, 2003 9:35:53 PM]

[edited by - Dublin on July 8, 2003 9:38:11 PM]
"poor is the pupil who does not surpass his master"- leonardo da vinci
I''d be glad to help, but you should be a bit more specific when describing your errors. It''s way much easier to help out that way. Anyways, this code should do the trick. If it still doesn''t work, tell us what your complier has to say about the code.


#include <windows.h>#include <iomanip>#include <iostream>#include <sstream>#include <time.h>#include <string>#include <vector>void aPrintFunction();int main(void){	std::cout.width(80);	std::cout.fill(''*'');	std::cout << "Before aPrintFunction" << std::endl;	aPrintFunction();			std::cout << "After aPrintFunction" << std::endl;		std::cout.width(80);		std::cout.fill(''*'');		return EXIT_SUCCESS;}void aPrintFunction(){	std::cout << std::endl;	std::cout.width(80);	std::cout.fill(''*'');}


This topic is closed to new replies.

Advertisement