在X $ C $的C 4 I / O重定向 [英] Redirecting I/O in Xcode 4
问题描述
我刚装X code 4,我试图从文件到我的C ++程序重定向输入。我已经使用通常的< infile.txt我尝试运行计划的参数一节中,但没有奏效。我可以就好了(通过编辑可执行参数)重定向输入和输出以x code 3。如何做到这一点在新版本中有什么建议?
I just installed Xcode 4 and I'm trying to redirect input from a file to my C++ program. I've tried using the usual "< infile.txt" in the "Arguments" section of my Run scheme, but that didn't work. I was able to redirect input and output in Xcode 3 just fine (by editing the arguments for the executable). Any suggestions on how to do this in the new version?
谢谢!
萨默尔
推荐答案
我拥有各类参数的测试,似乎在X code 4与参数的错误。
I tested with various types of Arguments and it appears that the XCode 4 have a bug with Arguments.
但有一个替代类似效果来模拟。您必须使用环境变量。
But there is one alternative to simulate with similar effect. You must use the Environment Variables.
添加环境变量的文件名要重定向:
Add a Environment Variable with the file name you want to redirect:
然后在你的code您必须将此文件重定向标准输入(CIN):
Then in your code you must "redirect" this file to the standard input (cin):
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main (int argc, const char * argv[])
{
ifstream arq(getenv("MYARQ"));
cin.rdbuf(arq.rdbuf());
string value;
cin >> value;
cout << value;
return 0;
}
这是它...只有2条线code的
that's it... only 2 lines of code
ifstream arq(getenv("MYARQ"));
cin.rdbuf(arq.rdbuf());
这不是最好的解决办法,但在X code具有这样的问题,这是唯一的解决办法!
it's not the best solution, but while xcode have this problem this is the only solution !
这篇关于在X $ C $的C 4 I / O重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!