0

I had written a C++ program on Xcode. the program compiled and ran just fine. No problems whatsoever.

For some reason, I had to re-install MasOSSierra. I made a backup of all my data, after which I did a clean-wipe and re-installed MacOSSierra.

Naturally, I re-installed XCode. My current version of Xcode is Version 8.3 (8E162).

Now when I run the old program, it won't run. The build succeeds with no error, but there is no display output.

This is the old program. It has a header file.

// **************************************************************

#include <iostream>
#include "PersonalExpenses.h"
bool addmore() {
std::string yn;
std::cout << "Would you like to add a name to the register or  quit(Press 0 to exit or 1 to continue)?";
std::getline(std::cin, yn);
return yn != "0";
}
int main(int argc, const char * argv[]) {

std::vector<PersonalExpenses> ledger;
while (addmore()) {
    PersonalExpenses udone;
    std::cin >> udone;
    ledger.push_back(udone);
}

for (const auto &item : ledger) {
    std::cout << "\n";
    std::cout << item << "\n";
}
}

// **************************************************************

After I run this program, I was expecting to see the following display in the output,

"Would you like to add a name ....."

But I get nothing.

So I modified the above program to something simple,

// **************************************************************
#include <iostream>

int main(int argc, const char * argv[]) {

int a = 10;
std::cout << "The value of 'a' is = " << a ; 
}
// **************************************************************

Still no output. But it seems like there is a flicker of an output, before it at all disappears within a fraction of a second. Interestingly, if i change one line to

std::cout << "The value of 'a' is = " << a << "\n" ;

Then the output displays just fine as ,

The value of 'a' is = 10

So what am I missing? Is there any setting that I have to change or is there anthing that I should do to get the old program to work. Thank you.

Big Head
  • 49
  • 6
  • It's probably to do with how prints are flushed by the OS. Some systems will wait for a \n to flush stdout buffers to the display window. something like fflush(stdout) may correct this (depending on OS). See also http://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin – PaulHK Apr 05 '17 at 03:55
  • @PaulHK thanks for the reply. I read the link and it sure seems like a recent Xcode update has caused this to happen. i've sent APPLE a bug report. I'll hope they'll fix it and provide an update. – Big Head Apr 07 '17 at 08:16

0 Answers0