Why don't structures work in Xcode when they work in Visual C ++? Need help!

For some reason, this very basic code will compile without errors in Visual C ++, but gives errors in Xcode. I will need to know why to continue working in Xcode for my Computer Science class.

#include <iostream>
#include <string>

using namespace std;

struct acct {        // bank account data
    int     num;      // account number
    string name;      // owner of account
    float   balance; // balance in account
};

int main() {

    acct account;

    cout << "Enter new account data: " << endl;
    cout << "Account number: ";
    cin  >> account.num;
    cout << "Account name: ";
    cin  >> account.name;
    cout << "Account balance: ";
    cin  >> account.balance;

    return 0;

}

This gives two errors, one of which says she expected ';' before the account (after main is declared), and the second this account was not declared for cin → account.num;

+3
source share
3 answers

: C , struct , ++ . , Unix acct - . , bank_account, , .

+13

"acct account"; "struct acct account"; . "acct" typedef , Visual ++ . XCode .

"typedef struct acct {...} acct;" acct typedef.

+1

I am having similar problems trying to use a variable called "log".

If you want to keep the name of your structure, try specifying only those elements that you want to use:

using std::cin;
using std::cout;
using std::endl;
0
source

Source: https://habr.com/ru/post/1720811/


All Articles