эта версия работает, посмотрите изменения, которые я внес.
первый
Я проверяю, есть ли у меня путь, прежде чем пытаться его открыть
секунда
проверьте, открывается ли файл с помощью if_open
EDIT измените чтение на std :: getline
РЕДАКТИРОВАТЬ
добавить std :: ios :: out в открытый режим, чтобы создать файл, если он не существует
#include <stdio.h>
#include <iostream>
#include<iostream>
#include<fstream>
using namespace std;
int main(int argc, char* argv[])
{
char arr[15];
ifstream file;
if (argc == 1)// <- moved it before opening the file
{
cout << "Enter file name from command line!";
return 0;
}
file.open(argv[1], ios::in|std::ios::out); //filename read from the command line and also create the file if it dosent exist
if(!file.is_open()) // <- second change
{
std::cout << "file not opening\n";
return 0;
}
int readState = 0;
std::string line;
while ( std::getline(file, string ) ) // <-- third fix
{
cout << arr;
readState++; //checking the system's state after each read()
}
else
{
cout << arr;
}
}
file.close();
return 0;
}
также, не используйте с использованием пространства имен std