-5
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    int k = 0;
    int n;
    int y[0];

    ifstream infile;
    infile.open("xxx.in.txt");
    infile.seekg(1);   //stores line 1 in n
    infile >> n;
    infile.seekg(2);     //stores line 2 in array
    infile >> y[0];
    infile.close();

    for( int x = 0; x < n; x++ )
        for( int j = 1; j < n; j++ )
            if ( y[x] > y[j] )
            {
                k = k++; //should probably use a flag
            }

    ofstream outfile;
    outfile.open("xxx.out.txt");
    outfile << k;
    outfile.close();

    return 0;
}

When i run the programme,it should run automatically because it doesnt need user input.But instead,when i run it,it doesnt do any of that,its just a blank command prompt

Ixrec
  • 966
  • 1
  • 7
  • 20
user4403101
  • 31
  • 1
  • 1
  • 3
  • 2
    Btw, `k = k++;` may not do what you think, regardless of what that may be ([see here](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points)). And I'm somewhat concerned by the comments and calls that you don't understand what the `seekg` member of an input stream does. `y`'s declaration is wrong. And *none* of the IO in this program is checked for success/failure whatsoever. – WhozCraig Jan 23 '15 at 21:48
  • 2
    `y` needs to have at least n elements, not 0. – Paul R Jan 23 '15 at 21:50
  • @ WhozCraig well if i use the seekg command in a wrong way i cant think of other ways to input from a specific line withouth user input – user4403101 Jan 23 '15 at 21:56
  • Post a sample of your input file *in your question* as a separate source list. I assume it isn't terribly large. Regardless, the rest of the issues identified will have to be fixed. A description of what this is supposed to be *doing* rather than leaving it to the reader to decipher would also be helpful in this question. – WhozCraig Jan 23 '15 at 21:57
  • @user4403101 The simplest non-fragile way to read a file line by line is while(getline(inputFile, line)) { ... } where "inputFile" is a std::ifstream and "line" is a std::string. – Ixrec Jan 23 '15 at 21:58
  • @ WhozCraig :line 1 consists of a number "n"(can take values up to 1mil),line two has numbers spaced apart that can be up to 1mil numbers – user4403101 Jan 23 '15 at 22:01
  • I don't know what you expected to happen, and it's not even that clear what _did_ happen. Can you please try to communicate the issue more precisely? – Lightness Races in Orbit Jan 23 '15 at 22:19
  • @ Ixrec I changed it to this: while(getline(infile,line)) { infile >> n; } but still get error – user4403101 Jan 24 '15 at 11:23

1 Answers1

2

You're reading from and writing to a file, not standard input/output.

Use std::cout if you want to print something to standard output, i.e. the console window.

Ixrec
  • 966
  • 1
  • 7
  • 20