cout going to stdout.txt

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

cout going to stdout.txt

Post by dandymcgee »

Does anyone know any reason why using cout << "string"; would be sending "string" the stdout.txt instead of the actual console windows?

If specific program details are needed let me know, but I figure this error is generic enough where maybe I'm just being stupid about something. It is 2:00 AM..
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
cypher1554R
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1124
Joined: Sun Jun 22, 2008 5:06 pm

Re: cout going to stdout.txt

Post by cypher1554R »

well, did you do this:

Code: Select all

std::ofstream cout("stdout.txt");
cout << "string";
instead of this:

Code: Select all

std::cout << "string";
..?
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: cout going to stdout.txt

Post by PixelP »

if youre coding something in sdl you cant do that, you cant use the console in a sdl program, all the output goes to stdout.txt.
it works in allegro thou.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: cout going to stdout.txt

Post by dandymcgee »

PixelP wrote:if youre coding something in sdl you cant do that, you cant use the console in a sdl program, all the output goes to stdout.txt.
it works in allegro thou.
But the weird part about it is a console window pops up with a blinking cursor, just the cout text doesn't display. I can still type in the filename and hit enter, then type q and hit enter and the program exits with status 3. Yet my debug output file (not stdout) tells me that the program received the file name and q command fine.

EDIT: I got it to work! Although it took a good bit of googling. Simply add the following line of code after SDL_Init():

Code: Select all

freopen( "CON", "w", stdout ); 
Seems to be working fine for me now.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: cout going to stdout.txt

Post by PixelP »

great.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: cout going to stdout.txt

Post by MarauderIIC »

Interesting, my console worked in my SDL app without any special code.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply