• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

Fractal

printf/cout, scanf/cin

20 posts in this topic

What''s the difference between cout and printf, or cin and scanf? Could I be any more dumber? (What do you mean, "No"?)
0

Share this post


Link to post
Share on other sites
I _think_ that printf, and scanf are from the days of C, and cout, and cin came along with C++... the differences, though i''m not too sure.

check the msdn, might help.
Scott

Email
Website

"If you try and don''t succeed, destroy all evidence that you tried."
0

Share this post


Link to post
Share on other sites
I can help a little CIN is a Console Input like sa you wanted a use to enter his/her age and COUT our prolly get Console Out puts a string out. and I think... Printf is a same thing as COUT.. not to sure about that one.
0

Share this post


Link to post
Share on other sites
Did that help you answer your question at all I hope that it did cause thats what I think hit means
0

Share this post


Link to post
Share on other sites
cout and cin are stream objects, while printf and scanf are functions.

Jesus is knocking at the door of your heart, won''''t you let him in?
0

Share this post


Link to post
Share on other sites
One bit of info (don''t quote me on this though):

the cout/cin/cerr are more reliable

but printf/scanf functions are very slightly quicker

Mind you if your using these function I can''t believe that there will be any relevent difference.
0

Share this post


Link to post
Share on other sites
quote:
Original post by xstreme2000
One bit of info (don''t quote me on this though):

the cout/cin/cerr are more reliable

but printf/scanf functions are very slightly quicker

Mind you if your using these function I can''t believe that there will be any relevent difference.


Neither is more reliable than the other, when used correctly. I don''t think there''s much speed difference either.

They are just two different interfaces to the standard input/output streams. There''s also write() and read(), if you like lower level printing.

It doesn''t matter which one you use in the slightest. Just don''t mix them in one program.
0

Share this post


Link to post
Share on other sites
In most implementations the C i/o library is faster with large amounts of data. That doesn''t mean your compiler or all compilers are the same way, they each have to implement the C and C++ standard libraries on their own. Neither is more reliable than the other, but the C++ version is more type safe (sometimes to your detriment, but C++ has its ways of getting around those problems).

[Resist Windows XP''s Invasive Production Activation Technology!]
0

Share this post


Link to post
Share on other sites
cin/cout are type safe. The type of the operand determines how IO is performed. With printf/scanf, you have to tell the function the type of its arguments seperately, so theres scope for errors like:

printf("%s", `a`);

Here, a single char is printed as a string, which is a bad thing because printf is expecting the address of a null terminated array of characters. Instead it gets a single char, which is probably a value below 127. The equivalent with cout can`t go wrong:

cout << `a`;

Thats the main advantage of cin/cout - they protect you from your own errors. The disadvantage is that the syntax is horrible if you want columns of data printed.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Krunk
The disadvantage is that the syntax is horrible if you want columns of data printed.


#include <iomanip>
...
// print age in an 8-cell column
// use blanks for padding
cout << setw(8) << setfill('' '') << age << endl;
0

Share this post


Link to post
Share on other sites
quote:
Original post by Fractal
Could I be any more dumber?


Yes, if you can come up with a use of English that is more incorrect than "more dumber"

---------
-WarMage
...instant smartass, just add smart and ass...

0

Share this post


Link to post
Share on other sites
quote:
Original post by Oluseyi
// print age in an 8-cell column
// use blanks for padding
cout << setw(8) << setfill(' ') << age << endl;


That`s not bad, but how about:
printf("%-20s%3d%4d%4d%3d", name, age, height, weight, shoesize);
vs
cout << setw(20) << setiosflags(ios::left) << name
<< setiosflags(ios::right) << setw(3) << age
<< setw(4) << height << setw(4) << weight
<< setw(3) << shoesize << endl;

Its a contrived example but it shows that with printf, layout is seperated from the values being output. This lets you see the column layout easily. With the cout version the layout commands are scattered through the statement. Cout is safer and more powerful, but too verbose for my liking when outputting tables.

Edited by - Krunk on October 24, 2001 5:42:16 PM
0

Share this post


Link to post
Share on other sites
quote:
Original post by Krunk
Its a contrived example but it shows that with printf, layout is seperated from the values being output. This lets you see the column layout easily. With the cout version the layout commands are scattered through the statement. Cout is safer and more powerful, but too verbose for my liking when outputting tables.


Point taken. I guess I almost never output tables.
0

Share this post


Link to post
Share on other sites
But what about text colors?

is there a way to modify the color of the text outputed when you cout?

If so how
0

Share this post


Link to post
Share on other sites
I removed my post after seing that most of the people here had already answered...

Sorry..


Edited by - cyberdrek on October 25, 2001 1:59:37 PM
0

Share this post


Link to post
Share on other sites
quote:
Original post by flip5577
But what about text colors?

is there a way to modify the color of the text outputed when you cout?


No. There isn''t when you use printf() either. Text attributes comes under console properties, and that''s very platform-specific.
0

Share this post


Link to post
Share on other sites
I think a big misunderstanding here is equating cout and cin (c++ classes) to printf and scanf (c functions)

cout and cin are just instances of a class. you rename these to what you want. what''s more powerful about it is they come from the fstream and iostream classes. YOu can even extended this to arrays of chars with strstream.

For example you can read in a file like so:

char buffer[1000];
//our array is now just like cout and cin!!!
strsteam my_buffer(buffer,sizeof(buffer);

fstream my_file("some.fil", ios::in);

char hold[100];
while (!my_file.eof())
{
my_file.getline(hold, sizeof(hold), "\n") // "\n" is a delimeter that can be any character

//so now we have a line from our file...stick in the buffer
my_buffer << hold;
}

//now we just stored the whole file into the my_buffer stream
//which points to char buffer[]...
//and now we can edit and jump aroun this buffer like a file
//example usage:

my_buffer.seekg(5); //skip five spaces in
my_buffer >> hold;
cout << hold; // should print out the first line (until it hits the "\n" in the array

anyways that''s just some sample stuff to use. the fstream and iostream and strstream are very powerful and can be used together for a lot of stuff. Just food for that.

Pactuul
0

Share this post


Link to post
Share on other sites
Uhmm...what makes printf and scanf modular? Structured I can see, but modular?

"A society without religion is like a crazed psychopath without a loaded .45"
0

Share this post


Link to post
Share on other sites
quote:
Original post by flip5577
is there a way to modify the color of the text outputed when you cout?


As Oluseyi said, coloured text is platform specific. If you`re lucky, you might find your console accepts ANSI Escape sequences. The consoles I`ve used in linux do, among others. They`re alright if you can be certain of the particular console the program will run in, but I wouldn`t use them in a shipping product
0

Share this post


Link to post
Share on other sites