macOS SieraのXcode 9.2でc++でテキストファイルを生成するプログラムを作成しました。実行するとエラーもなく、問題はなさそうですが実際にファイルが作成されません。
-----------------------
#include <fstream>
using namespace std;
int main(void)
{
ofstream myText("Hello.txt");
myText << "Hello Text!" << endl;
myText.close();
return 0;
}
-----------------------
プロジェクトのソースファイルと同じパスを予想して確認してますがありません。
ファイルを検索してみても見つかりませんでした。
-----------------------
ofstream myText("Hello.txt");
-----------------------
部分を
-----------------------
ofstream myText("/Users/xxxxxx/Documents/Hello.txt");
-----------------------
の絶対パスにすると作成されました。
現在の作動パスを認識してないようでした。
stackoverflowで解決法を見つけたので整理します。
C++ Program in Xcode not outputting simple text file using outFile
XcodeプロジェクトのSchemeで作業ディレクトリの設定が必要でした。
1)実行ボタン(RUN)の右側のプロジェクト名部分をクリック>>Edit Scheme
2)Run>>Options>>Working Directory
Use custom working directoryをチェックしてパス選択、設定
ちゃんと生成されました!
Xcode의 c++프로젝트에서 ofstream으로 파일작성이 안될때 처리
-----------------------
#include <fstream>
using namespace std;
int main(void)
{
ofstream myText("Hello.txt");
myText << "Hello Text!" << endl;
myText.close();
return 0;
}
-----------------------
プロジェクトのソースファイルと同じパスを予想して確認してますがありません。
ファイルを検索してみても見つかりませんでした。
-----------------------
ofstream myText("Hello.txt");
-----------------------
部分を
-----------------------
ofstream myText("/Users/xxxxxx/Documents/Hello.txt");
-----------------------
の絶対パスにすると作成されました。
現在の作動パスを認識してないようでした。
stackoverflowで解決法を見つけたので整理します。
C++ Program in Xcode not outputting simple text file using outFile
XcodeプロジェクトのSchemeで作業ディレクトリの設定が必要でした。
1)実行ボタン(RUN)の右側のプロジェクト名部分をクリック>>Edit Scheme
2)Run>>Options>>Working Directory
Use custom working directoryをチェックしてパス選択、設定
ちゃんと生成されました!
Xcode의 c++프로젝트에서 ofstream으로 파일작성이 안될때 처리
댓글
댓글 쓰기