0
votes
#include <iostream>
#include <limits>
#include <string>

using namespace std;

void wczytajOsobe(string imie[], string nazwisko[], int wiek[])
{
    int i=2;
    for(int indeks=0;i>indeks;indeks++)
    {
    cout << "Podaj Imie: " << endl;
    getline(cin, imie[indeks]);
    cout << "Podaj Naziwsko: " << endl;
    getline(cin, nazwisko[indeks]);
    }
}

void wypiszOsobe(string imie[], string nazwisko[], int wiek[])
{
    int i=2;
    for(int indeks=0;i>indeks;indeks++)
    {
        cout << imie[indeks];
        cout << nazwisko[indeks];
        cout << wiek[indeks];
    }
}

int main()
{
    string imie[2];
    string nazwisko[2];
    int wiek[2];
    for( int i = 0; i < 2; i++ )
         wczytajOsobe(imie[i], nazwisko[i], wiek[i]);

    for( int i = 0; i < 2; i++ )
         wypiszOsobe(imie[ i ], nazwisko[ i ], wiek[ i ] );

    system("PAUSE");
    return 0;
}

This is my code and i have problem with|36|error: cannot convert 'std::__cxx11::string {aka std::__cxx11::basic_string}' to 'std::__cxx11::string* {aka std::__cxx11::basic_string}' for argument '1' to 'void wczytajOsobe(std::__cxx11::string, std::__cxx11::string*, int*)'| can somebody help me with that issue ?

1
Both your functions are expecting string[], but you are parsing in a single string. The error is telling you that you cannot convert a string to a pointer to strings. - Nathan

1 Answers

1
votes

You have two functions defined as:

void wczytajOsobe(string imie[], string nazwisko[], int wiek[]);
void wypiszOsobe(string imie[], string nazwisko[], int wiek[]);

Because arrays decay to pointers when passed to functions, the parameter types are actually:

void wczytajOsobe(string *imie, string *nazwisko, int *wiek);
void wypiszOsobe(string *imie, string *nazwisko, int *wiek);

When you call the functions like:

for( int i = 0; i < 2; i++ )
    wczytajOsobe(imie[i], nazwisko[i], wiek[i]);

You're not passing arrays but individual array elements. That's why the error message says it can't convert std::string to std::string*.

You don't need those loops in main(). You can just call the functions as:

int main()
{
    string imie[2];
    string nazwisko[2];
    int wiek[2];

    wczytajOsobe(imie, nazwisko, wiek);
    wypiszOsobe(imie, nazwisko, wiek);

    system("PAUSE");
    return 0;
}

Note that I'm just passing the arrays to the functions.