1. <small id='8KB0S'></small><noframes id='8KB0S'>

      <i id='8KB0S'><tr id='8KB0S'><dt id='8KB0S'><q id='8KB0S'><span id='8KB0S'><b id='8KB0S'><form id='8KB0S'><ins id='8KB0S'></ins><ul id='8KB0S'></ul><sub id='8KB0S'></sub></form><legend id='8KB0S'></legend><bdo id='8KB0S'><pre id='8KB0S'><center id='8KB0S'></center></pre></bdo></b><th id='8KB0S'></th></span></q></dt></tr></i><div id='8KB0S'><tfoot id='8KB0S'></tfoot><dl id='8KB0S'><fieldset id='8KB0S'></fieldset></dl></div>

        <bdo id='8KB0S'></bdo><ul id='8KB0S'></ul>
      <tfoot id='8KB0S'></tfoot>
      <legend id='8KB0S'><style id='8KB0S'><dir id='8KB0S'><q id='8KB0S'></q></dir></style></legend>

        CLion C++ 无法读取/打开项目目录中的 .txt 文件

        CLion C++ can#39;t read/open .txt file in project directory(CLion C++ 无法读取/打开项目目录中的 .txt 文件)
          <tbody id='S3dEt'></tbody>
      1. <tfoot id='S3dEt'></tfoot>

      2. <legend id='S3dEt'><style id='S3dEt'><dir id='S3dEt'><q id='S3dEt'></q></dir></style></legend>

          <small id='S3dEt'></small><noframes id='S3dEt'>

          • <bdo id='S3dEt'></bdo><ul id='S3dEt'></ul>
                  <i id='S3dEt'><tr id='S3dEt'><dt id='S3dEt'><q id='S3dEt'><span id='S3dEt'><b id='S3dEt'><form id='S3dEt'><ins id='S3dEt'></ins><ul id='S3dEt'></ul><sub id='S3dEt'></sub></form><legend id='S3dEt'></legend><bdo id='S3dEt'><pre id='S3dEt'><center id='S3dEt'></center></pre></bdo></b><th id='S3dEt'></th></span></q></dt></tr></i><div id='S3dEt'><tfoot id='S3dEt'></tfoot><dl id='S3dEt'><fieldset id='S3dEt'></fieldset></dl></div>
                  本文介绍了CLion C++ 无法读取/打开项目目录中的 .txt 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的项目目录中有一个 .txt 文件,我创建并填充了数据.

                  I have a .txt file in my project directory that I made and populated with data.

                  目录结构如下:

                  /Users/asd/ClionProjects/ProjectWithTemplates/
                  main.cpp
                  cmake
                  twoday.txt
                  

                  这是我的代码:

                  #include <iostream>
                  #include <array>
                  #include <cmath>
                  #include <fstream>
                  
                  
                  using namespace std;
                  
                  /* print array prototype */
                  template <size_t N>
                  void printArray(const array<double , N> & arr);
                  
                  /* mean function prototype */
                  template <size_t N>
                  double meanArray(const array<double , N> & arr);
                  
                  /* standard deviation prototype */
                  template <size_t N>
                  double sDeviation(const array<double , N> & arr);
                  
                  int main() {
                  
                      string date1;
                      string date2;
                  
                      array<double, 24> day1Temps;
                      array<double, 24> day2Temps;
                      array<double, 3> testarr = {75,70,65};
                  
                  /* TESTING PURPOSES */
                      printArray(testarr);
                      sDeviation(testarr);
                      cout << "standard deviation of array is: " << sDeviation(testarr) << endl;
                      cout << "mean of array is: " << meanArray(testarr) << endl;
                  /* END TESTING */
                  
                      ifstream inputFile;
                      inputFile.open("twoday.txt");
                  
                      if(inputFile.is_open())
                      {
                          inputFile >> date1;
                          inputFile >> date2;
                  
                          for(int i = 1; i < day1Temps.size(); ++i)
                          {
                              inputFile >> day1Temps[i];
                          }
                  
                          for (int j = 1; j < day2Temps.size(); ++j) {
                              inputFile >> day2Temps[j];
                          }
                      } else cout << "File unable to open. File does not exist." << endl;
                  
                  
                      return 0;
                  }
                  
                  /* print array defination */
                  template <size_t N>
                  void printArray(const array<double , N> & arr){
                  
                      for(const auto & i : arr)
                      {
                          cout << i << " ";
                      }
                      cout << endl;
                  }
                  
                  /* mean function defination */
                  template <size_t N>
                  double meanArray(const array<double , N> & arr){
                  
                      double sum;
                  
                      for (const auto & i : arr) {
                          sum+=i;
                      }
                  
                      return sum/arr.size();
                  }
                  
                  /* standard deviation defination */
                  template <size_t N>
                  double sDeviation(const array<double , N> & arr){
                  
                      double mean = meanArray(arr);
                      double total;
                  
                      for (const auto & i : arr){
                          total+=pow(i - mean, 2);
                      }
                      return sqrt(total/arr.size());
                  }
                  

                  除了我的文件 IO 之外,其他一切都很好.很奇怪.

                  Eveything else works fine besides my file IO. Very strange.

                  添加一些细节……更多细节?:(

                  adding some details..............more details? :(

                  推荐答案

                  if inputFile.is_open() 总是返回 false, inputFile.open("twoday.txt"); 没有正确打开文件,大概是因为找不到 "twoday.txt"

                  if inputFile.is_open() always returns false, inputFile.open("twoday.txt"); is not opening the file correctly, presumably because it can't find "twoday.txt"

                  如果您使用的是 Linux,请尝试设置显式路径,例如 "c:/path/twoday.txt""/path/twoday.txt".您也可以尝试编写一个文件来查看它出现的位置,或者使用更奇特的方法返回当前路径.

                  Try setting an explicit path like "c:/path/twoday.txt" or "/path/twoday.txt" if you're using Linux. You could also try writing a file instead to see where it shows up, or something more exotic to return the current path.

                  这篇关于CLion C++ 无法读取/打开项目目录中的 .txt 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                  • <tfoot id='9WbLg'></tfoot>
                    • <legend id='9WbLg'><style id='9WbLg'><dir id='9WbLg'><q id='9WbLg'></q></dir></style></legend>

                        • <bdo id='9WbLg'></bdo><ul id='9WbLg'></ul>
                            <tbody id='9WbLg'></tbody>

                            <i id='9WbLg'><tr id='9WbLg'><dt id='9WbLg'><q id='9WbLg'><span id='9WbLg'><b id='9WbLg'><form id='9WbLg'><ins id='9WbLg'></ins><ul id='9WbLg'></ul><sub id='9WbLg'></sub></form><legend id='9WbLg'></legend><bdo id='9WbLg'><pre id='9WbLg'><center id='9WbLg'></center></pre></bdo></b><th id='9WbLg'></th></span></q></dt></tr></i><div id='9WbLg'><tfoot id='9WbLg'></tfoot><dl id='9WbLg'><fieldset id='9WbLg'></fieldset></dl></div>

                            <small id='9WbLg'></small><noframes id='9WbLg'>