Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Passing a string to a function

#include <iostream>

using namespace std;

void display(char *);
void display(string);

int main()
{
    string str1;
    char str[100];

    cout << "Enter a string: ";
    getline(cin, str1);

    cout << "Enter another string: ";
    cin.get(str, 100, '
');

    display(str1);
    display(str);
    return 0;
}

void display(char s[])
{
    cout << "Entered char array is: " << s << endl;
}

void display(string s)
{
    cout << "Entered string is: " << s << endl;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: xor linked list 
Cpp :: [3,2,4,-1,-4] 
Cpp :: c ++ loop 
Cpp :: convert c program to c++ online 
Cpp :: 136. Single Number leetcode solution in c++ 
Cpp :: how to merge string array in C++ 
Cpp :: C++ if...else 
Cpp :: stp 
Cpp :: break input stream into words 
Cpp :: sro in c++ 
Cpp :: how to test if char in = to another in c++ 
Cpp :: c++ CRL multiline string 
Cpp :: catalan numbers c++ 
Cpp :: decising how many numbers after comma c++ 
Cpp :: castin in C++ 
Cpp :: arduino jumper programmieren 
Cpp :: floating point exception 
Cpp :: 1672. Richest Customer Wealth leetcode solution in c++ 
Cpp :: 2160. Minimum Sum of Four Digit Number After Splitting Digits leetcode solution in c++ 
Cpp :: Required Length 
Cpp :: sort sub vector, sort range of vector c++ 
Cpp :: error when using template base class members 
Cpp :: ex:c++ gcc start adress 
Cpp :: if c++ 
Cpp :: vector remove class 
Cpp :: Default code in C++ for VSCode 
Cpp :: x += c++ 
Cpp :: cout<<"helloworld"<<endl problem 
C :: unity change transparency script 
C :: pygame draw transparent rectangle 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =