gpt4 book ai didi

c++ - 使用 Xcode 在 C++ 中编写文件并使用终端运行

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:12:25 29 4
gpt4 key购买 nike

我是编程新手,我给自己买了一本自助书,但这本书是为 Windows 设计的。到目前为止,我基本上能够翻译,但我在编写/附加文件并通过终端运行它们时遇到了困难。我想知道是否有人可以为我翻译这些台词。这些行是我被告知在命令提示符/终端中输入的内容。

C:\MyPrograms> c++ write.cpp -o write.exe

C:\MyPrograms>写入

#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
string poem = "\n\tI never saw a man who looked" ;
poem.append("\n\tWith such a wistful eye") ;
poem.append("\n\tUpon that little tent of blue") ;
poem.append("\n\tWhich prisoners call the sky") ;

ofstream writer("poem.txt") ;

if (! writer)
{
cout << "Error opening file for output" << endl ;
return -1 ; //signal an error then exit the program.
}

writer << poem << endl ; // write output
writer.close() ; // close filestream.

return 0 ;
}

这是我正在尝试运行的名为 write.cpp 的程序,请帮忙谢谢!

最佳答案

在 OS X 上,终端中的第一行是:

g++ write.cpp -o write

第二行是:

./write

第一行编译您的代码并创建一个名为write 的可执行文件。第二行运行可执行文件。

关于c++ - 使用 Xcode 在 C++ 中编写文件并使用终端运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39001695/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com