I have .in file in project directory when i use absolute path to open the file it works but relative path not working.
directoy content
main.cpp
CMakeLists.txt
milk2.in
CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(project)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp )
add_executable(project ${SOURCE_FILES})
main.cpp
#include <iostream>
using namespace std;
int main() {
pair<int, int> periods[5000];
int lineCount = 0;
freopen("milk2.in", "r", stdin);
cin >> lineCount;
for (int j = 0; j < lineCount; ++j) {
cin >> periods[j].first >> periods[j].second;
}
int startNode = periods[0].first, endNode = periods[0].second, milkMax = 0, freeMax = 0;
for (int i = 1; i < lineCount; ++i) {
if (periods[i].first <= endNode) {
endNode = periods[i].second;
if ((endNode - startNode) > milkMax)
milkMax = endNode - startNode;
} else {
if ((periods[i].first - endNode) > freeMax)
freeMax = periods[i].first - endNode;
}
}
cout << milkMax << " " << freeMax << endl;
}
there is no errors in the code but can,t read files contents with relative path.