0
#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. Commented Apr 20, 2020 at 8:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.