1
I’m trying to make a program that reads a string and int and stores its values in one struct
and then print it on the screen, I’m still learning, forgive me if it’s a very obvious mistake.
Code:
#include<iostream>
using namespace std;
struct teste {
int num;
char str[16];
};
int main(){
struct teste var[3];
int i;
for(i = 0; i < 3; i++){
cin >> var[i].num;
cin.getline(var[i].str, 16);
//fgets(var[i].str, 15, stdin);
}
int j;
for(j = 0; j < 3; j++){
cout << endl << var[j].num << endl;
cout << var[j].str << endl;
}
return 0;
}