久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

代碼在 g++ 中運行完美,但在 Xcode 中卻不是 - 找

Code runs perfect in g++ but not in Xcode - Cannot find File(代碼在 g++ 中運行完美,但在 Xcode 中卻不是 - 找不到文件)
本文介紹了代碼在 g++ 中運行完美,但在 Xcode 中卻不是 - 找不到文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我創建了一個包含內容的文本文件.它與 cpp 文件位于同一文件夾中.我已經多次確認該文件存在.當我運行 g++ 時,編譯并運行它會找到該文件.當我在 Xcode 中運行它時,它不起作用.如果找不到文件.

I have created a text file with content. It is located in the same folder as the cpp files. And I have confirmed several times that the file exists. When I run g++, compile and run it finds the file. When I run it in Xcode, it does not work. If fails to find the file.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
  string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 

  return 0;
}

推薦答案

您的文件無法打開,因為 XCode 從 IDE 中的默認 build 位置啟動,該位置實際上是某個位置的臨時目錄你的磁盤.如果您想在啟動時將工作目錄更改為其他內容(例如可以找到文件的位置):

Your file fails to open because XCode launches from the IDE in the default build location, which is actually a temporary directory off somewhere on your disk. If you want change the working directory at launch-time to something else (like the location where your files can be found):

  1. 選擇產品/編輯方案...菜單選項.
  2. 在左側列表中選擇運行架構.
  3. 在右窗格的底部 選項 標簽應該是工作目錄"選項.選中復選框并將自定義工作目錄設置為您知道的地方(您的/Users/yourname"主目錄是我使用的一個不錯的地方).
  4. 確保從 IDE 執行程序所需的任何當前目錄"數據文件都在此目錄中.
  1. Select the Product/Edit Scheme... menu option.
  2. Select the Run schema in the left list.
  3. At the bottom Options tab on the right pane should be a "Working Directory" option. Check the checkbox and set the custom working directory to someplace you know (your "/Users/yourname" home directory is a decent place that I use).
  4. Make sure any "current directory" data files you need for your program execution from the IDE are in this directory.

如果您沒有看到,這也是您可以配置同一對話框的命令行參數(在另一個選項卡上)的地方.

And in case you didn't see it, this is also the place where you can configure command-line arguments (on another tab) of the same dialog.

這篇關于代碼在 g++ 中運行完美,但在 Xcode 中卻不是 - 找不到文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What is the fastest way to transpose a matrix in C++?(在 C++ 中轉置矩陣的最快方法是什么?)
Sorting zipped (locked) containers in C++ using boost or the STL(使用 boost 或 STL 在 C++ 中對壓縮(鎖定)容器進行排序)
Rotating a point about another point (2D)(圍繞另一個點旋轉一個點 (2D))
Image Processing: Algorithm Improvement for #39;Coca-Cola Can#39; Recognition(圖像處理:Coca-Cola Can 識別的算法改進)
How do I construct an ISO 8601 datetime in C++?(如何在 C++ 中構建 ISO 8601 日期時間?)
Sort list using STL sort function(使用 STL 排序功能對列表進行排序)
主站蜘蛛池模板: 欧美午夜精品 | 久久久久国产精品午夜一区 | 国产美女高潮 | 高清免费在线 | 男插女下体视频 | 久久精品网 | 国产情侣啪啪 | 精品国产视频 | 97综合在线 | 99视频在线播放 | 狠狠插天天干 | 中文字幕高清av | 日韩毛片 | 久久这里只有精品首页 | 亚洲一区二区三区在线 | 日韩精品视频在线 | 成人av免费 | 日本精品一区二区在线观看 | 一级片av | 狼人伊人影院 | 中文字幕一区二区三区四区五区 | 久草综合在线视频 | 亚洲 中文 欧美 日韩 在线观看 | 丝袜一区二区三区 | 国产欧美一区二区三区在线播放 | 一区免费| 国产精品一区一区三区 | 精品欧美一区免费观看α√ | 日韩欧美国产一区二区三区 | 欧美理论 | 中文字幕精品一区二区三区精品 | 91av在线视频观看 | 午夜视频免费在线观看 | 免费的av| 欧美日韩精品久久久免费观看 | 国产精品福利网站 | 九九国产| 人人玩人人干 | 中文字幕乱码一区二区三区 | 91久久精品国产91久久性色tv | 99精品久久久久久中文字幕 |