[Help]I just begin :p

Posts 1–9 of 9 · Page 1 of 1
[Help]I just begin :p
Hi, I have an error that may look obious for you, but I can't find it can you tell me why i get this error?

Code:
#include <iostream>

using namespace std;

struct Caract
{
    char prenom[] = "";
    char nom[] = "";
    int age = 0;
};

void Profiler(Caract &profiled);

int main()
{
    Caract profil;

    Profiler(profil);

    cout << "Votre nom complet est : " << profil.prenom << " " << profil.nom << endl << "Et vous avez " << profil.age << " ans ." << endl;

    return 0;
}

void Profiler(Caract &profiled)
{
    cout << "Quel est votre prenom ? " << endl;
    cin >> profiled.prenom;
    cout << "Quel est votre nom ? " << endl;
    cin >> profiled.nom;
    cout << "Quel age avez-vous ? " << endl;
    cin >> profiled.age;
}

error :

Code:
 Visual Basic\Premier Programme\main.cpp|7|error: ISO C++ forbids initialization of member 'prenom'|
 Visual Basic\Premier Programme\main.cpp|7|error: making 'prenom' static|
 Visual Basic\Premier Programme\main.cpp|7|error: invalid in-class initialization of static data member of non-integral type 'char [0]'|
 Visual Basic\Premier Programme\main.cpp|8|error: ISO C++ forbids initialization of member 'nom'|
 Visual Basic\Premier Programme\main.cpp|8|error: making 'nom' static|
 Visual Basic\Premier Programme\main.cpp|8|error: invalid in-class initialization of static data member of non-integral type 'char [0]'|
 Visual Basic\Premier Programme\main.cpp|9|error: ISO C++ forbids initialization of member 'age'|
 Visual Basic\Premier Programme\main.cpp|9|error: making 'age' static|
 Visual Basic\Premier Programme\main.cpp|9|error: ISO C++ forbids in-class initialization of non-const static member 'age'|
 Visual Basic\Premier Programme\main.cpp||In function 'int main()':|
 Visual Basic\Premier Programme\main.cpp|20|error: 'struct Caract' has no member named 'prenom'|
 Visual Basic\Premier Programme\main.cpp|20|error: 'struct Caract' has no member named 'nom'|
 Visual Basic\Premier Programme\main.cpp||In function 'void Profiler(Caract&)':|
 Visual Basic\Premier Programme\main.cpp|28|error: 'struct Caract' has no member named 'prenom'|
 Visual Basic\Premier Programme\main.cpp|30|error: 'struct Caract' has no member named 'nom'|
||=== Build finished: 13 errors, 0 warnings ===|
Code:
#include <iostream>

using namespace std;

struct Caract
{
    char prenom[10];
    char nom[10];
    int age;
};

void Profiler(Caract &profiled);

int main()
{
    Caract profil;

    Profiler(profil);

    cout << "Votre nom complet est : " << profil.prenom << " " << profil.nom << endl << "Et vous avez " << profil.age << " ans ." << endl;

    return 0;
}

void Profiler(Caract &profiled)
{
    cout << "Quel est votre prenom ? " << endl;
    cin >> profiled.prenom;
    cout << "Quel est votre nom ? " << endl;
    cin >> profiled.nom;
    cout << "Quel age avez-vous ? " << endl;
    cin >> profiled.age;
}
fixed,

you need to declare the array size... and you can't initialize a var inside a struct
Thank u for help ^^
It wasn't obious to me at all.

I recommend using strings once u learn classes and structures and stuff. Though there is a slight overhead, its usually worth the cost of not having to self manage char arrays.
Quote Originally Posted by why06 View Post
It wasn't obious to me at all.

I recommend using strings once u learn classes and structures and stuff. Though there is a slight overhead, its usually worth the cost of not having to self manage char arrays.
I didn't learn strings
Quote Originally Posted by Gab View Post
I didn't learn strings
you will soon ^^
Your right, I just learned the basic of strings ^^
you should put the arrays [number here]
you did:
Code:
char prenom[] = "";
    char nom[] = "";
    int age = 0;
try to make it like this:
Code:
char prenom[10] = "";
    char nom[99] = "";
    int age = 0;
i hope this helped
Quote Originally Posted by AeroMan View Post
you should put the arrays [number here]
you did:
Code:
char prenom[] = "";
    char nom[] = "";
    int age = 0;
try to make it like this:
Code:
char prenom[10] = "";
    char nom[99] = "";
    int age = 0;
i hope this helped
his problem was fixed already, and what you posted would still give an error because you cant initialize vars inside structs
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us