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

代碼在 g++ 中運(yùn)行完美,但在 Xcode 中卻不是 - 找

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

問題描述

我創(chuàng)建了一個包含內(nèi)容的文本文件.它與 cpp 文件位于同一文件夾中.我已經(jīng)多次確認(rèn)該文件存在.當(dāng)我運(yùn)行 g++ 時,編譯并運(yùn)行它會找到該文件.當(dāng)我在 Xcode 中運(yùn)行它時,它不起作用.如果找不到文件.

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;
}

推薦答案

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

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. 選擇產(chǎn)品/編輯方案...菜單選項(xiàng).
  2. 在左側(cè)列表中選擇運(yùn)行架構(gòu).
  3. 在右窗格的底部 選項(xiàng) 標(biāo)簽應(yīng)該是工作目錄"選項(xiàng).選中復(fù)選框并將自定義工作目錄設(shè)置為您知道的地方(您的/Users/yourname"主目錄是我使用的一個不錯的地方).
  4. 確保從 IDE 執(zhí)行程序所需的任何當(dāng)前目錄"數(shù)據(jù)文件都在此目錄中.
  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.

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

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.

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

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

相關(guān)文檔推薦

What is the fastest way to transpose a matrix in C++?(在 C++ 中轉(zhuǎn)置矩陣的最快方法是什么?)
Sorting zipped (locked) containers in C++ using boost or the STL(使用 boost 或 STL 在 C++ 中對壓縮(鎖定)容器進(jìn)行排序)
Rotating a point about another point (2D)(圍繞另一個點(diǎn)旋轉(zhuǎn)一個點(diǎn) (2D))
Image Processing: Algorithm Improvement for #39;Coca-Cola Can#39; Recognition(圖像處理:Coca-Cola Can 識別的算法改進(jìn))
How do I construct an ISO 8601 datetime in C++?(如何在 C++ 中構(gòu)建 ISO 8601 日期時間?)
Sort list using STL sort function(使用 STL 排序功能對列表進(jìn)行排序)
主站蜘蛛池模板: 操碰97| 二区三区视频 | 午夜久久久久久 | 亚洲小视频在线观看 | 日本少妇做爰全过程毛片 | 亚洲毛片视频 | 97视频免费在线观看 | 日韩三级一区二区 | 欧美一级片网站 | 亚洲色欲色欲www在线观看 | 99热国产在线 | 伊人国产在线 | 成人免费毛片嘿嘿连载视频 | 97人人草 | 青青草久久 | 国产精品自拍小视频 | 欧洲色综合 | 亚洲精品视频免费在线观看 | 免费看成人片 | 91视频一区二区三区 | 国产成人精品一区二区三区在线观看 | 一区二区三区成人 | 亚洲久久久久久 | 国产精品1区2区 | 一级片黄色 | av片在线免费观看 | 天天搞天天搞 | 精品一区在线播放 | 精品亚洲一区二区三区 | 国产精品美女毛片真酒店 | 日韩毛片免费 | 久久久在线 | 亚洲第一黄网 | 少妇中文字幕 | av天天干| 高潮毛片又色又爽免费 | 欧美国产在线观看 | 欧美日韩一区二区三区 | 日韩欧美一区二区三区久久婷婷 | 99热网站 | 18视频在线观看男男 |