Ok, so I know how structure look but don't know how to use it on my code I need help setting up the structure and reading in the text and printing the results but with name and letter swapped positions.
int main()
{
//Cannot figure out how to do structures and Properly format the output to the file
struct mine
{
int num1;
char data[10];
string what;
};
//declare a string to hold the text
string name,letter,integer,integer2;
int x,y,users;
//creates the data file
ofstream outfile("Test 3.txt");
cout << "Enter the amount of users to add: ";
cin >> users;
cin.ignore();
// loop for choosing amount of users to add
for(x=0;x<users;x++)
{
cout<<"Enter fullname last name first: ";
getline(cin, name);
cout<<"Enter Capital N or S: ";
getline(cin, letter);
cout<<"Enter first integer: ";
getline(cin, integer);
cout<<"Enter second integer: ";
getline(cin, integer2);
cout <<endl;
//prints to the file
outfile<<name<<right<<setw(15)<<letter
<<right<<setw(20)<<integer
<<right<<setw(25)<<integer2
<<right<<setw(30)<<"\n";
}
//close the output file
outfile.close();
ifstream myfile ("test3.txt");
//Dont Know how to read into and array of structure
system("pause");
return 0;
}
int main()
{
//Cannot figure out how to do structures and Properly format the output to the file
struct mine
{
int num1;
char data[10];
string what;
};
mine all_users[100]; // Note: max 100 ursers / index for 0 to 99 not 100
//declare a string to hold the text
string name,letter,integer,integer2;
int x,y,users;
//creates the data file
ofstream outfile("Test 3.txt");
cout << "Enter the amount of users to add: ";
cin >> users;
cin.ignore();
// loop for choosing amount of users to add
for(x=0;x<users;x++)
{
cout<<"Enter what: ";
getline(cin, all_users[x].what); // Note: access the member what from struct mine
cout<<"Enter fullname last name first: ";
getline(cin, name);
cout<<"Enter Capital N or S: ";
getline(cin, letter);
cout<<"Enter first integer: ";
getline(cin, integer);
cout<<"Enter second integer: ";
getline(cin, integer2);
cout <<endl;
//prints to the file
outfile<<name<<right<<setw(15)<<letter
<<right<<setw(20)<<integer
<<right<<setw(25)<<integer2
<<right<<setw(30)<<"\n";
}
//close the output file
outfile.close();
ifstream myfile ("test3.txt");
//Dont Know how to read into and array of structure
system("pause");
return 0;
}