Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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;
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #Passing #string #function
ADD COMMENT
Topic
Name
7+9 =