0

[@tl;dr] I have Visual Studio Ultimate 2013 and Eclipse Neon v2(C++), and I need to redirect the output of my program using DOS format, but I have no idea how.

Im on Windows btw.

OK.. so I have this class assignment where I have to write a program like this:

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

/* Check if the Character is lower case or not */
bool checkLowerCase(char c) {
    if (c >= 'a' && c <= 'z') return true;
    return false;
}

/*
* If there is any lower case letter, it will replace it will a upper case.
* example:
*   "Tauros" will become "TAUROS"
*   "auHU" will become "AUHU"
*/
string fixer(string s)
{
    char right = ('a' - 'A');
    string a = s;
    for (unsigned int i = 0; i < a.length(); i++)
    {
        if (checkLowerCase(a[i])) {
            a[i] = a[i] - right;
        }
    }
    return a;
}

int main(void)
{
    while (1) //infinite loop
    {
        string line;
        getline(cin, line);
        if (!cin) { //Professor wants us to only check end of input like this
            return 0;
        }
        line = fixer(line);
        cout << line << endl;
    }
}

The input was:

aaaaaa
bbbbbb
cccccc

The output was:

aaaaaa
AAAAAA
bbbbbb
BBBBBB
cccccc
CCCCCC

Thanks for reading this far. Ok, so here's my problem. The output is all messed up, so I need to redirect the output somewhere else (at least for testing).

I know how to do that using , , holding each line in a Array of String, reallocating if needed and then print what is on the array, but, unfortunately, my lecturer demanded us only to include and Ohh, I dont know if it will matter, but we may not use char*, only the class string.

My lecturer told us that we have to use DOS format. But I have no clue how to do that. If someone can tell me how to do either redirect the input or the output is finee...

I have in my PC both Eclipse C++ (working glitchy) and Visual Studio Ultimate 2013 (working fine).

[Edit] Im on Windows.

AGAIN: I may only include and

For more information, here's his slide on DOS format.

*For testing purposes one redirect to/from a file
*DOS formatting will have unexpected consequences
   – The end-of-line is the CR-NL combination
   – A line read from the file will end with CR
   – The CR character is the command to erase the
   previous line!

./main < infile.txt                   Input is from infile.txt
./main > outfile.txt                  Output is to outfile.txt
./main < infile.txt > outfile.txt     Both input and output are redirected

1 Answers1

0

OK, so... I found instructions that helped me here:

https://msdn.microsoft.com/en-us/library/ms235639.aspx

I opened my project folder in the VisualStudio, created 2 files.

input.txt

output.txt

I opened the Developer Command Prompt for VS2013 that I had in my PC.

cd ["C://my_project_path"]       //go to my project folder
cl /EHsc file.cpp                
/* 
    cl /EHsc will compile my program (I think it only compiles one file at a time. 
    I have yet to test it).
*/
file < input.txt > output.txt    // this command will run my program

So when I run my program like this... Instead of waiting for an input from keyboard, my program will read input.txt as the standard input. And when I try to print something to the output, it will write on the output.txt instead.

[EDIT] at the end of the link I pasted, there are explanations on how to compile multiple files and what exacly does the /EHsc do exacly

Community
  • 1
  • 1