LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-10-2003, 07:49 PM   #1
liguorir
Member
 
Registered: May 2003
Posts: 256

Rep: Reputation: 30
Talking C++/C Counterparts.


What are C++ counterparts for the following in C :

arrays
printf
malloc
free
strcpy
strncpy
memcpy
memmove
qsort

Thanks,

Robert Liguori
 
Old 07-11-2003, 11:06 AM   #2
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
Re: C++/C Counterparts.

C: C++ counterpart

arrays: std::vector, or use arrays the same as in C. There are many more containers in the STL.

printf : std::cout

malloc: new
free: delete

strcpy: = (assignment), or one of std::string's constructors.
strncpy: with std::string, you don't need to worry about string length (or the null terminator) anymore.
memcpy: don't know
memmove: don't know
You can still use null-terminated arrays of char like in C (a.k.a. C-strings) in C++ if you really wanted these functions (#include <cstring>).

qsort: std::sort, or a sort member function for the particular container you're using.

Lyle
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Counterparts Eyaw_Nayr Linux - Software 1 08-15-2004 06:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration