c++第一次操作文件,找不到文件,求解

用VS2022打开文件,但是找不到文件,求解。

#include
int main() {
    freopen_s("in.txt","r",stdin);
    freopen_s("out.txt","w",stdout);
    int temp, sum = 0;
    while (scanf_s("%d", &temp) == 1)

    {
        sum = sum + temp;
    }
    printf("%d\n", sum);
    fclose(stdin); fclose(stdout);
    return 0;
}

img

我在这个程序的文件路径里都放了同名的文件,但是都说找不到。

img

#include <fstream>

int main() {
  int temp, sum = 0;
  std::ifstream ifile("in.txt");
  while (ifile >> temp)
    sum += temp;
  std::ofstream ofile("out.txt");
  ofile << sum << '\n';
  return 0;
}

放到调试文件夹里面
Debug文件夹

freopen_s()函数的使用有误,参考:https://blog.csdn.net/weixin_44391390/article/details/89186971