Programming Articles - Page 2004 of 3363

Pair in C++ Standard Template Library (STL)

Ayush Gupta
Updated on 14-Apr-2020 12:11:55

534 Views

In this tutorial, we will be discussing a program to understand pair in C++ Standard Template Library.Pair is a container defined in the utility header that contains two values. It is used to combine two values and associate them even if they are of different types.Example Live Demo#include #include using namespace std; int main(){    //initializing a pair    pair PAIR1 ;    PAIR1.first = 100;    PAIR1.second = 'G' ;    cout

Output Iterators in C++ programming

Ayush Gupta
Updated on 14-Apr-2020 12:09:22

170 Views

In this tutorial, we will be discussing a program to understand output iterators in C++.Output iterators are a part of the major five iterators. They function opposite of the input iterators in a way that they can be assigned values but can’t be accessed to fetch values.Example Live Demo#include #include using namespace std; int main(){    vectorv1 = {1, 2, 3, 4, 5};    //declaring iterator    vector::iterator i1;    for (i1=v1.begin();i1!=v1.end();++i1){       *i1 = 1;    }    return 0; }OutputNo output, because we cannot access values of output operators

Ordered Set and GNU C++ PBDS

Ayush Gupta
Updated on 14-Apr-2020 12:07:48

2K+ Views

In this tutorial, we will be discussing a program to understand ordered set and GNU C++ PBDS.Ordered set is a policy based structure other than those in the STL library. The ordered set keeps all the elements in a sorted order and doesn’t allow duplicate values.Example Live Demo#include using namespace std; #include #include using namespace __gnu_pbds; #define ordered_set tree int main(){    //declaring ordered set    ordered_set o_set;    o_set.insert(5);    o_set.insert(1);    o_set.insert(2);    cout

Order of Constructor/ Destructor Call in C++

Ayush Gupta
Updated on 14-Apr-2020 12:04:57

564 Views

In this tutorial, we will be discussing a program to understand the order of constructor/ destructor in C++.Order of constructor/destructor refers to the pattern in which the constructors of various classes are called during inheritance of classes.Example Live Demo#include using namespace std; //parent class class Parent{    public:    Parent(){       cout

Operator overloading in C++ to print contents of vector, map, pair ..

Ayush Gupta
Updated on 14-Apr-2020 12:02:26

628 Views

In this tutorial, we will be discussing a program to understand operator overloading in C++ to print contents of vector, map and pair.Operator overloading is the function of operators which gives them the ability to act on User defined objects and work accordingly in a similar fashion.ExampleVector Live Demo#include #include using namespace std; template ostream& operator

Merge operations using STL in C++ | merge(), includes(), set_union(), set_intersection(), set_difference(), inplace_merge

Ayush Gupta
Updated on 14-Apr-2020 11:58:44

170 Views

In this tutorial, we will be discussing a program to understand the various merge operations using STL in C++.The merge() function is used to merge two sorted containers in a way that the new container is also sorted. Further includes() is used to check if the elements from first container are present in the second one.Example Live Demo#include #include #include using namespace std; int main(){    vector v1 = {1, 3, 4, 5, 20, 30};    vector v2 = {1, 5, 6, 7, 25, 30};    //initializing resultant vector    vector v3(12);    merge(v1.begin(), v1.end(), v2.begin(),    v2.end(), v3.begin());    cout

How can we implement Flow API using Publisher-Subscriber in Java 9?

raja
Updated on 14-Apr-2020 10:31:19

2K+ Views

Flow API (java.util.concurrent.Flow) has introduced in Java 9. It helps to understand different ways in which the Publisher and Subscriber interfaces interact to perform desired operations.Flow API consists of Publisher, Subscriber, Subscription, and Processor interfaces, which can be based on reactive stream specification.In the below example, we can implement Flow API by using Publisher-Subscriber interfaces.Exampleimport java.util.concurrent.Flow.Publisher; import java.util.concurrent.Flow.Subscriber; import java.util.concurrent.Flow.Subscription; public class FlowAPITest {    public static void main(String args[]) {       Publisher publisherSync = new Publisher() {   // Create publisher          @Override          public void subscribe(Subscriber

What is text origin in JavaFX?

Maruthi Krishna
Updated on 14-Apr-2020 08:53:51

413 Views

In addition to the local coordinate system for positioning its nodes, JavaFX provides an additional coordinate system for the text node.The textOrigin property specifies the origin of the coordinates of the text node in the parent coordinate system. You can set values to this property using the setTextOrigin() method. This method accepts one of the constants of the enum named VPos. This enum contains 4 constants namely: BASELINE, BOTTOM, CENTER and, TOP.Exampleimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; import javafx.application.Application; import javafx.geometry.VPos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Text; public class TextOriginExample extends Application {   ... Read More

How to strike through and underline text in JavaFX?

Maruthi Krishna
Updated on 14-Apr-2020 08:50:24

4K+ Views

In JavaFX, the text node is represented by the Javafx.scene.text.Text class. To insert/display text in JavaFx window you need to −Instantiate the Text class.Set the basic properties like position and text string, using the setter methods or, bypassing them as arguments to the constructor.Add the created node to the Group object.The strikethrough property of the javafx.scene.text.Text class determines whether each line of the text should have a straight line passing through the middle of it. You can set the value to this property using the setStrikeThrough() method. It accepts a boolean value. You can strike though the text (node) by ... Read More

How to adjust the line spacing in the text node in JavaFX?

Maruthi Krishna
Updated on 14-Apr-2020 08:48:00

2K+ Views

The line spacing property of the javafx.scene.text.The text class specifies the line spacing between the lines of the text (node) vertically.You can set the value to this property using the setLineSpacing() method. This method accepts a boolean value as a parameter and sets the specified space between the lines (vertically).Exampleimport java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Scanner; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; public class TextSpacing extends Application {    public void start(Stage stage) throws FileNotFoundException {       //Reading the contents of a text file.       InputStream inputStream ... Read More

Advertisements