int main(int argc, char *argV[]){
istream *br;
ifstream inFile;
if(argc == 2){
inFile.open(argV[1]);
if(inFile.is_open()){
cout << "file opened."; //if only "file opened" has an "\n then only it will print
br = &inFile; //and the program will freeze right after printing it
}
}
else if(argc <= 1){
br = &cin;
}
else{
cout << "Unrecognized commands";
}
cout << "test"; //having \n here allows the program to reach this line of code and
cout << "test2\n"; //everything before it
Something strange is happening. Unless "\n" is included in the string nothing will print to standard out. For example. the cout << "test" & "test2\n" at the bottom enables the program to reach those lines of code and will cout everything up to that point, e.g. the "file opened" line because test2 has \n and file opened precedes it. If they are changed to just cout "test1" test2" the program will not output anything, including the "file opened". Additionally, if I change "file opened" to "file opened\n" then that will print, but if the test1 and test2 do not have a \n they will not print, since they are after the \n in "file opened."