Connecting Tech Pros Worldwide Help | Site Map

I need some translations from C to C++

Newbie
 
Join Date: Oct 2009
Posts: 9
#1: 2 Weeks Ago
Just these:
printf();
scanf();
fread();
fwrite();
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 380
#2: 2 Weeks Ago

re: I need some translations from C to C++


#include <stdio>
std::printf(...);
?
Member
 
Join Date: Jan 2008
Posts: 38
#3: 2 Weeks Ago

re: I need some translations from C to C++


Should be #include <cstdio> I think.

He or she might be asking for cout/cin in place of printf/scanf? But like newb said if you really want to use the original c functions just use them directly in your C++ prog.
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#4: 2 Weeks Ago

re: I need some translations from C to C++


Quote:

Originally Posted by newb16

#include <stdio>
std::printf(...);
?


Nope. What you show is C plus there is no <stdio> include. I believe you meant <cstdio>.

To the OP:

The functions you mention are replaced by operator<< and operator>> depending upon whether you are insrtingor extracting data from a stream.

The functions you mention can be used only with the built-on types of C whereas the operator<< and operator>> can be written by you to work woth any type of object.
Newbie
 
Join Date: Oct 2009
Posts: 9
#5: 2 Weeks Ago

re: I need some translations from C to C++


Quote:

Originally Posted by weaknessforcats View Post

Nope. What you show is C plus there is no <stdio> include. I believe you meant <cstdio>.

To the OP:

The functions you mention are replaced by operator<< and operator>> depending upon whether you are insrtingor extracting data from a stream.

The functions you mention can be used only with the built-on types of C whereas the operator<< and operator>> can be written by you to work woth any type of object.

Well if you would be so kind as to tell me what those functions are exactly?
Like printf("Hello world");
How do I write it with the << >> operators?
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,387
#6: 2 Weeks Ago

re: I need some translations from C to C++


Expand|Select|Wrap|Line Numbers
  1. cout << "Hello World";
Newbie
 
Join Date: Oct 2009
Posts: 9
#7: 2 Weeks Ago

re: I need some translations from C to C++


Quote:

Originally Posted by RedSon View Post

Expand|Select|Wrap|Line Numbers
  1. cout << "Hello World";

Thanks.
Now how about the other 3 functions?
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,387
#8: 2 Weeks Ago

re: I need some translations from C to C++


scanf would be
Expand|Select|Wrap|Line Numbers
  1. cin >> var;
And for the rest it is the same just use a file stream instead of cout and cin. Or even better, you could use google to help you look up usage!
Reply