473,659 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using stdio.h in a C++ program

44 New Member
Hello..

Is it okay to use functions such as setvbuf (that is defined in stdio.h) in a C++ program?
I include stdio.h in the program and it works. Yet, I wonder if its okay.. stdio.h is a part of the standard C library and not standard C++ library, if I'm not wrong.
I also want to know if many such other functions can be used in C++ programming. Is there a clear line between the standard libraries for C and C++? Is using either in the other's programs a bad thing to do?

(I'm using GNU's DJGPP on Windows XP).

Thanks a ton. I love bytes.

Hanaa.
Mar 1 '09 #1
6 4870
JosAH
11,448 Recognized Expert MVP
C functions are supposed to work in C++. Some functions can't be mixed, e.g. malloc/free and new/delete should be kept far from each other. C++ has more flexible functions/classes and methods. From a more purist point of view there is no need to use the functions available in stdio.h, C++ has its alternatives that can do what their C counterparts do and more. Bookmark this site for a convenient reference.

kind regards,

Jos
Mar 1 '09 #2
newb16
687 Contributor
setvbuf is mentioned in the c++ standard, and is expected to work as described in the C standard unless compiler/library itself has bugs.
Mar 2 '09 #3
hanaa
44 New Member
Thank you..
1)Would you also tell me where I can find the Standards?

2) Would someone answer the others questions too, the questions in my first post here (if using C's functions in C++ programs in a bad idea).
Mar 2 '09 #4
manontheedge
175 New Member
@hanaa

I'm not sure about "finding standards", but generally, when working with C++, you can tell C and C++ apart by the header files. C++ doesn't use header files with a '.h', for example #include <stdio.h> is obviously a C standard ( because of the .h ), though obviously if you create a header file yourself, you'll use a '.h', but that's different.

In general, mixing C with C++ is frowned upon. It's just bad practice, though you will find those who do it.
Mar 2 '09 #5
hanaa
44 New Member
Oh I didnt know the .h thing. Strange. I always wrote <iostream.h> in Turbo c++ version 3.0. Yeah , but in GCC, it accepts only <iostream>.

Hmmm. Okay. But I found nothing equivalent to setvbuf() (in stdio.h) in any other header file. Is there any, in a C++ header file?

Thank you.
Mar 3 '09 #6
newb16
687 Contributor
#include <cstdio>

It, in turn, most likely incudes stdio.h
Mar 3 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
25221
by: Nick Li | last post by:
Hi, I am trying to writing a c program to send email using system() function call on Unix(Sun Solaris). I tried the following: #include <stdio.h> #include <stdio.h> int main(void) {
3
18368
by: Harayasu | last post by:
Hi, Using fgets() I can read from stdin and with fputs() I can write to stdout. Now I have two programs, one writing to stdin and the other one reading from stdin. And I would like the second program to read the characters the first program has written to stdin, but I don't get it how to do this. The program which writes to stdin:
24
5847
by: Charles Ulrich | last post by:
Greetings, I hope my greenness isn't showing too bad by asking this, but I ran across this trivial program today that left me flabbergasted: #define MESSAGE "This account is currently not available.\n" int main(int argc, char *argv) {
42
9870
by: Prashanth Badabagni | last post by:
Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
6
3491
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being written. /* Book name : File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp Program discription: Adding name,Address to customer_record SETUP PROGRAM
16
3257
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is that I'm not very experienced with pointers, pointers to pointers and the like and I got 4 compiler warnings + I don't completely understand how to build this "compact matrix" (see later).
8
11868
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
89
6035
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
8
2000
by: Cuthbert | last post by:
Hi folks, This question is a little deep into memory management of microprocessor. How do we know the memory arrangement using in microprocessors? Top-Bottom or Bottom-Top? For example, the "Top-Bottom" is arranging memory resource from higher address to lower address.
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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...
1
8531
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,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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.