久久久久久久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 排序功能對列表進行排序)
主站蜘蛛池模板: 啪啪综合网 | 亚洲精品国产一区 | 国产精品久久久久久久7电影 | 日韩欧美在线播放 | 亚洲欧洲精品一区 | 久久久精品久 | 巨大荫蒂视频欧美另类大 | a级在线免费观看 | 成人夜晚看av | 欧美日韩毛片 | 午夜影院在线观看免费 | 成人不卡| 黄色一级视频免费 | 日本视频在线播放 | 一区二区三区播放 | 在线免费av电影 | 亚洲一区中文字幕 | 国产精品久久久久久久久久久免费看 | 免费毛片网 | 亚洲一区二区在线播放 | 插插插干干干 | 国产精品久久久久久婷婷天堂 | 亚洲成人免费网址 | 免费在线观看av的网站 | 色婷婷综合成人av | 一区二区三区免费观看 | 成人免费在线观看 | 黄色在线播放视频 | 亚洲一区二区三区福利 | 91豆花视频 | 粉嫩粉嫩芽的虎白女18在线视频 | 日韩精品一区二区三区高清免费 | 久久成人人人人精品欧 | 日韩欧美天堂 | 日本一区二区三区在线观看 | 久久久精品久久久 | 日本成年免费网站 | 国产1区2区3区 | 91黄色免费看 | 久久狠狠| 日韩一区二区在线视频 |