1

So recently I have been developing a program that asks the user some questions and asks for their reply, it then stores it to an array, and writes it out to an output file, although I don't get the information the user inputs but this code thing: 0x4080c0. Can someone please help me, here is my code as well:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

string q1 = "Distance Flown:";
string q2 = "Total Fuel Used:";
string q3 = "Total Flight Time:";
string q4 = "Number Of Passengers:";
string q5 = "Total Profit:";
string q6 = "Any futher comments goes here:";

string logAwensers[6];

int main()
{
cout << "Please enter your pilot log here."<< endl;
cout << q1 << endl;
getline(cin, logAwensers[0]);
cout << q2 << endl;
getline(cin, logAwensers[1]);
cout << q3 << endl;
getline(cin, logAwensers[2]);
cout << q4 << endl;
getline(cin, logAwensers[3]);
cout << q5 << endl;
getline(cin, logAwensers[4]);
cout << q6 << endl;
getline(cin, logAwensers[5]);

cout << logAwensers << endl;
ofstream writer("PilotLog.txt", ios::app);

if(! writer)
{
    cout << "Error writing file" << endl;
}

    return -1;
}
writer << logAwensers << endl;
writer.close();
return 0;
}

Thanks.

4
  • You should indent your code properly. The } after return -1; is closing main function. And please, don't use global variables. Commented Jan 10, 2018 at 3:24
  • Oh okay sorry, I forgot to mention i'm new to programming. Commented Jan 10, 2018 at 3:26
  • And, you are currently writting the address of the array. Use a for loop, or write each element one by one. (No need to mention, it's obvious ;)) Commented Jan 10, 2018 at 3:26
  • Unrelated to your question, but probably good fundamental business to learn/gain awareness of: Why is “using namespace std” considered bad practice? Commented Jan 10, 2018 at 4:17

1 Answer 1

3

Instead of:

cout << logAwensers << endl;

Try something like:

for (const auto &a : logAwensers)
{
    cout << a << endl;
}
Sign up to request clarification or add additional context in comments.

8 Comments

No copy needed here -> auto const &.
I'll leave that one to the compiler.
Leave what? auto deduction doesn't keep const and & qualifiers.
I don't see what would stop the compiler from taking care of that. The code is fairly simple. Anyway, I'll modify it just to make it easier for you to go to sleep tonight.
Thanks you very much.
|

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.