Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Dublin

Console output?

This topic is 5493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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(''*'');
}



Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!