C++ Definition and 81 Discussions

C++ () is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation. It is almost always implemented as a compiled language, and many vendors provide C++ compilers, including the Free Software Foundation, LLVM, Microsoft, Intel, Oracle, and IBM, so it is available on many platforms.C++ was designed with an orientation toward system programming and embedded, resource-constrained software and large systems, with performance, efficiency, and flexibility of use as its design highlights. C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applications, including desktop applications, video games, servers (e.g. e-commerce, web search, or databases), and performance-critical applications (e.g. telephone switches or space probes).C++ is standardized by the International Organization for Standardization (ISO), with the latest standard version ratified and published by ISO in December 2020 as ISO/IEC 14882:2020 (informally known as C++20). The C++ programming language was initially standardized in 1998 as ISO/IEC 14882:1998, which was then amended by the C++03, C++11, C++14, and C++17 standards. The current C++20 standard supersedes these with new features and an enlarged standard library. Before the initial standardization in 1998, C++ was developed by Danish computer scientist Bjarne Stroustrup at Bell Labs since 1979 as an extension of the C language; he wanted an efficient and flexible language similar to C that also provided high-level features for program organization. Since 2012, C++ has been on a three-year release schedule with C++23 as the next planned standard.

View More On Wikipedia.org
  1. D

    Euler Method in C++

    Summary: Problem with Euler Method in C++ Hello, I have a very difficult problem for me (a beginner in programming) how to make the version of the euler method presented in c ++ with the void, float functions, so that the program will calculate from the data that I enter during the program...
  2. user366312

    Polymer simulation source code in C++ and Python

    I am absolutely new to Polymer simulation. I am trying to understand the simulation by analyzing source code written by others. Can anyone tell me what are the differences between the following three source code in terms of their objectives? Monte-Carlo-simulation-of-polymers...
  3. S

    I Phase singularities in C++

    hello i would like to ask how to implement phase singularities in C++. thanks very much.
  4. B

    Why are structs used for linked lists and classes used for binary trees?

    Why are struct use for linked list and classes used for binary tree. honestly what is the different between a class and a struct? I have a teacher one tell me that a class was a struct on steroids. but what does that really mean ?
  5. Z

    Wrong solution order using Runge Kutta 4

    Hi, I'm trying to simulate a 3-body problem with a star at the center of reference system and 2 body orbiting around it using Runge Kutta 4. The 2 bodies perturb each other orbits gravitationally, so my ode system is actually a coupled armonic oscillator and I evaluate the solution of both...
  6. A

    Comp Sci Template for the STL

    in .h file I write like this: namespace board{ template <class T> class BAdapter : public AbstractB{ public: BAdapter(); BAdapter(int x){ x=6; setSize(x); } virtual void setSize(int receivedSize){...
  7. S

    Converting State Vectors to Keplerian Orbital Elements for Binary Objects

    Homework Statement:: I'm working on a personal project to convert objects from a simulation using state vectors for position and velocity to Keplerian orbital elements (semimajor axis, eccentricity, argument of periapsis, etc.). However, the equations I am using do not calculate the...
  8. A

    Comp Sci Class and vector

    I am now learning C ++ and trying to learn class and vector. I'm trying to write code, but I got an error. this is my class and enum class: enum class state: char{ empty='.', filled_with_x='x', filled_with_o='o'}; class class1{ private: class class2{ class2()...
  9. A

    Comp Sci Cin.ignore remove first character

    if(count%2==0){ //for user 1 cout<<"User 1"<<endl; cout << "Please enter your move: "; cin.ignore(); getline(cin,str); //do something } else if (count%2!=0){ //for user 2 cout<<"User 2"<<endl; cout << "Please enter your move: "; cin.ignore(); getline(cin,str); //do something...
  10. A

    Comp Sci Generate random numbers in C++

    I want to generate random numbers in C++. I do not want to use C library function (`<cstdlib> <ctime> (time.h)` ) and class. So I cannot use `rand()` function in C. I want to generate random integer numbers and I guess I can use `<random>` library in C++11. How can I use this generate random...
  11. Adec

    Comp Sci Galaxy simulation with the velocity Verlet algorithm

    To simulate the trayectories of solar systems around a black hole (i.e. a galaxy) I have 3 classes in C++: cSystem, cBlackHole and cGalaxy. cSystem assigns initial values of position, velocity, etc to a solar system. cBlackHole does the same but just for the black hole. And cGalaxy mixes...
  12. E

    C/C++ C++ Program Suddenly Ends after Reading Huge Data

    I have written a C++ code in Visual Studio 2019 that requires an input tab-delimited text file and outputs a text file that is also tab-delimited. The data within the text file are stored in a vector and then it will perform calculations, whose results will then be written in a text file as...
  13. Vick

    C/C++ Need help with C++ code

    I'm not at all C++ literate, but I need to understand what a C++ code is doing for a math problem regarding the Stieltjes polynomials. Especially, I want to know what is happening to the "num" and "den" in the code; the code is in this link: Stieltjes
  14. B

    Second programming language to get under the belt: python vs C

    Hello everybody, I am a master student in Theoretical Chemistry and I am working in the DFT realm. Both TDDFT and DFT applied to extended systems (eg. using QUANTUM ESPRESSO). Of course I work with these softwares from a end-user point of view, not as a developer. But anyway, even if some of...
  15. S

    C# Loops to compare many rows between 2 worksheets in C#?

    Hello All, I took it upon myself to create a tool for my job that xref 2 excel worksheets on 2 different workbooks. Customers send us parts and they're wanting the leadtimes for them. We have a weekly report that has all part numbers with their leadtimes. My goal is to create a GUI in C# that...
  16. adamaero

    Compiles, and motor driver shields work individually--but not together

    I don't have a debugger yet, but my company is getting one... In the mean time, I've been un/commenting out parts of Mbed's code. Their Hello World program is available from this website, and it can be used directly in their online IDE by clicking "Import Program"...
  17. JayZ0198

    Multipurpose software that keeps C, Python, DSP, .... in the same file

    I’ve been looking for a certain type of software that can host programming (preferably C or Python) and other process that I’m going to need such as DSP, DSP filters, diagrams (3D graphs, charts,…), and text editing within the same file. It’s mainly so that I can incorporate and use each one...
  18. J

    Comp Sci How do you read two files in the same program in C++?

    My matrix text files can vary from 1x1 to 10x10 (Another file will be given when the code gets tested but it's all square matrices) I'm stuck here. #include <iostream> #include <fstream> #include <string> using namespace std; int main() { const int MAXI = 10; int x, y, z...
  19. J

    Comp Sci C++ How to read char + number

    Hello, the text file I'm trying to read is formatted as below: x y z point1 number number number I have used getline to discard the first...
  20. J

    Comp Sci C++ File Output

    I have computed the total length of a 3D triangle and its area. The code is shown below. I want to use file output instead of cout. The file name, cw2task1output, was just given as part of the task, in this case should I make an empty text file named cw2task1output then attach it to the resource...
  21. davidfur

    MPI parallel code speed-up sucks

    Hey guys, I parallelized my code, written in C++, with the MPI library. Unfortunately, the speed-up I get saturates at x6, with increasing number of cores. Whereas, in theory, the speed-up should really be nearly linear. To understand where the bottlenecks come from, I drilled down the code to...
  22. M

    Dynamic Programming - Restoring white space between words in a file

    All the white space among words in a text file was lost. Write a C++ program which using dynamic programming to get all of the possible original text files (i.e. with white spaces between words) and rank them in order of likelihood with the best possible runtime. You have a text file of...
  23. J

    Comp Sci C++ Opening a txt file using argc and argv

    Homework Statement I have a complete code that calculates distances between point 1(x1,y1,z1) and other points(from 2nd up to more than 100) and the nth point that results in minimum distance and the minimum distance between point 1 and nth point. The code is below. The code is 100% correct...
  24. J

    Comp Sci C++ Reading a data file

    Homework Statement I have successfully opened and discarded the headers. Then I calculated the distances between point 1 and others and the minimum distance as well. However, I am not sure how to make the code work for more than 4 points. The attached text file is what I am trying to read and...
  25. J

    Comp Sci C++ program to read an input file with multiple headers

    Homework Statement Write a program that can read an input file with a simple header. The Attempt at a Solution #include <iostream> #include <fstream> using namespace std; int main() { ifstream inFile; inFile.open("Data"); //Check for error if (inFile.fail()) {...
  26. YoungPhysicist

    Using cin like scanf()

    if I want to read to integer a and b and they are in a formation of a@b, I CAN SIMPLY USE scanf(%d@%d,&a,&b) to read the input. But how should I do that in c++(with cin)?
  27. SchroedingersLion

    Setting up an FCC lattice in a simulation

    Greetings, for a Monte Carlo simulation of N hard spheres, I want to set up the initial configuration as a fcc lattice. I am thinking about how to do it most efficiently. Here is the lattice structure: The 3 lattice vectors, each one pointing to a different type of the 12 nearest neighbors...
  28. B

    0s and 1s Array problem

    Homework Statement A house has n x m rooms (n and m natural numbers, n>=2 and m>=2) and is represented as a 2 dimensional Array with n rows(0 to n-1)and m columns(0 to m-1).The room at line i( 0 <= i <= n-1) and column j ( 0 <= j <= m-1 ) is identified by the pair of numbers (i,j).All rooms...
  29. D

    Comp Sci Working with classes and vectors in C++

    Homework Statement Write a BinaryTree Class using these specifications: A Class Node represents a standard node of the tree with fields and a constructor like given below: int start, end; const Complex* value; //I will provide more information about Complex later because that was the...
  30. R

    Comp Sci Velocity Verlet applied to solar system with C++

    Homework Statement Hello, I am attempting to use the velocity Verlet algorithm of integration applied to the solar system in c++. My goal is be able to use the outputted position components in a plot to see if the trajectory of my object is elliptical/parabolic/hyperbolic resulting from the...
  31. D

    Algorithm to matrix product MSR format

    Hi everybody, I'm writing some algebra classes in C++ , Now I'm implementing the modified sparse row matrix , I wrote all most all of the class, but I didn't find the way saving computing time to perform the product of two Modified sparse row matrix .. if you don't know it you can read in the...
  32. D

    C/C++ Question about a specific class method in C++

    Create a class DecimalN which holds decimal numbers using dynamic arrays. Implement a constructor DecimalN::DecimalN(char* decimal) so that it can be created like for example DecimalN number("23.5698"). Create two class functions (methods) that given the number n it shift the number n places...
  33. D

    Comp Sci Using a custom constructor in a C++ class

    Homework Statement I am quite new to C++. I have completed my C course and am now taking a C++ course at my college. The first problem i encountered is with classes and custom made constructors. In the first part of the problem I am supposed to create a class with a field which is a dynamic...
  34. E

    Comp Sci C++ overloading function

    Homework Statement [/B] Write a function fForceOfGravity, with return type double and with two double parameters for mass (m) and gravity (g). Parameter gravity must be initialized to 9.81. The force of gravity is given by the formula F=mg. Call these functions in the main () as follows: cout...
  35. C

    Comp Sci C++ program, fork gymnastics

    This is what I did but I'm getting an infinite loop of the reversed string whenever I run the program. I don't know why #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> /* for fork() and getpid() */ #include <sys/types.h> #include <iostream> using namespace std...
  36. S

    File contents deletion

    ok i wrote my code but the whole file gets deleted instead of the required values. else if(option==5) { int rno; fstream w1;fstream e1; e1.open("temp.dat",ios::in|ios::out|ios::binary)...
  37. E

    Write a function that will find a temperature....

    Hi everybody, I seem to be having trouble coding a function that returns the integer value at which degrees celsius is equivalent to degrees fahrenheit. Here is the question: Write a function that will find a temperature that is the same in both Fahrenheit and Celsius. First define two...
  38. C

    Comp Sci Book Database Implementation C++

    I began by creating 2 classes. A book class and a course class that contains any necessary info about the book and course respectively class bookClass{ private: string theISBN; string thebookName; string thebookAuthor; double thebookCost; int...
  39. M

    C/C++ Velocity Verlet C++ implementation

    I have been working on implementing a solar system system simulator in C++ - but am getting incorrect results on the order of 10^10 km, and it seems that the planets are moving directly away from the sun. I suspect that there is a mistake in the integrator (Velocity Verlet) that I have posted...
  40. Fabio Kopp

    How to integrate when one of the limits is a variable?

    I'm trying to integrate a simple function (x*y) using the Romberg method. Question 1: I want to integrate only x and maintain the argument y present in the rest of calculation, like a global variable. In fortran 77 I would use common. Question 2: How to integrate using arguments in the...
  41. Const@ntine

    Comp Sci Cylinder Area (C++)

    Homework Statement Find the are of the cylinder, by creating a program in C++. 2. The attempt at a solution So far I have: #include <iostream> using namespace std; const double PI = 3.14159; class point { protected: int x; int y; public: point() { } point (int xvalue...
  42. N

    How to add confg file to allow UHD drive set priority?

    I have Ettus B210 and trying to add 1 line configuration file "/etc/security/limits.conf" which will allow UHD drive to set priority. So , I typed this command to edit file: gksudo gedit /etc/security/limits.conf and add: #@student hard nproc 20 #@faculty soft...
  43. Const@ntine

    Comp Sci C++: Method of Minimum Squares used for System Solving

    Homework Statement Okay, this one is a bit big, and I'm attempting a translation, so I'm going to post a TL;DR version at the bottom just to be sure. Anyway, here goes: While doing an experiment, we write down the values of a physical/natural size y, for various values of a physical/natural...
  44. Const@ntine

    Comp Sci Function Derivatives & Sines (C++)

    Homework Statement Okay, I'm going to "cheat" a bit and add two programs here, but I don't want to clutter the board by making two threads. Anyways, here goes: (1) The value of the sine of an angle, measured in rads, can be found using the following formula: sin(x) = x - x3/3! + x5/5! - ...
  45. B

    C/C++ How to open a window in just C++ (g++ linux) ?

    I want to open a window in just c++. Now I can do this easily with SDL with just 2-3 lines of code, but I want to learn how to open a window in c++ without any library, I mean like plain c++ nothing else. I searched this on google but results yield nothing of my interest. There has to be a...
  46. AHashemi

    C/C++ Optimize C++ to use for computational physics?

    Hi I'm studying 2nd year for a bachelor's degree in physics and I'm interested in programming (Beginner C++ programmer). I have already done simulations like harmonic motions, Ising model etc but I know this can go further and I need help with that. I use Ubuntu for programming with c++. (GCC...
  47. Z

    What is the best textbook for learning C++?

    I've taken a class in C++ and we used Bjarne Stroustrup's Programming: Principles and Practice Using C++. We only got to the point to where we were just starting to learn about pointers, so I still consider myself a beginner. C++ is my first programming language. I really like how Bjarne...
  48. LeftMyHeartInErebor

    Courses C++ and fortran?

    My program only requires that I take C++ or Fortran. It seems like most students I have asked are only taking C++, I'm thinking of doing both. I'm planning on asking my advisor as well, but so far I've been really underwhelmed with my meetings with him. Thoughts? Thanks in advance!
  49. B

    How can link external libraries from the cmd?

    I am familiar with linking external libraries in IDE like Eclipse, Netbeans etc. But in my college they use use vim for programming on Linux. To learn more about vim editor I installed it on my home computer.I can compile basic C++ programs on it with one or two .cpp/.h files. I think it is...
  50. Hughng

    Comp Sci Difference between two dates C++

    Homework Statement I am trying to solve a problem that asks me to give the total days between two dates. I have to take care of the some matters between those two dates such as leap years and the way of inputting the years by the users. (For example, if you input 1 and 17, the code will still...
Top