Visual Studio社区2017 C ++启动而不调试不使用命令参数 [英] Visual Studio Community 2017 C++Start Without Debugging Not Working with Command Arguments
问题描述
我正在运行Visual Studio Community 2017版本15.9.3
我点击了File-> New-> Project->我创建了一个新的空控制台项目。 Windows桌面向导
然后选择"控制台应用程序"和"空项目"。
我写了一个简单的程序
#include< iostream>使用namespace std
;
int main()
{
char a;
cin>>一个;
cout<<一个;
}
并按下Ctrl + F5。
我输入'e',这是输出:
e
C:\Peter\_CPP \ hello \Debug \ hello.exe(流程4808)退出,代码为0.
按任意键关闭此窗口。 。 。
我按了一个键,程序退出。
然后我创建了一个名为"h.txt"的文件。并转到Project-> Properties-> Configuration Properties-> Debugging-> Command Arguments
并使用"< h.txt"对于命令参数。
这次,当我按下Ctrl + F5时,控制台出现并立即关闭。
如何解决这个问题?
谢谢
嗨Yeeter,
欢迎来到MSDN论坛。
如果您想要的是将.txt文件添加到命令参数并使用它的数据。我建议您只输入"test.txt"而不是"< test.txt"。
同时,您可以按照以下步骤通过命令参数获取数据。
- 右键单击解决方案资源管理器中的项目,选择添加一个新项目,选择TextFile(.txt)并将其命名为test.txt。在其中写下一些数据:para1 para2 3 4 5 6 7 8 9 ...
- 在命令参数中键入"test.txt"而不是"< test.txt"。
- 编写如下代码:
#include
< iostream>
#include
< string>
#include
< fstream>
#include
< sstream>
使用
namespace 标准;
int main( int
argc ,
char *
argv []){
//获取数据
fstream f;
f.open( argv [1]);
字符串 line;
getline(f,line);
cout
<< "内容为:" <<
line << endl;
//使用这种方式获取数据的每一项
字符串 str1,str2,str3;
std :: istringstream
是(线);
is
>> str1
>> str2
>> str3;
cout
<< str1
<<
","
<< str2
<<
","
<< str3
<< endl;
//防止窗口消失
" pause" );
返回 0;
}
通过这种方式,您可以使用txt文件的数据来满足您的需求。
最好的问候,
萨拉跨度>
I am running Visual Studio Community 2017 version 15.9.3
I made a new empty Console Project by clicking File->New->Project->Windows Desktop Wizard
and then choosing "Console Application" and "Empty Project".
I wrote a simple program
#include <iostream> using namespace std; int main() { char a; cin >> a; cout << a; }
and pressed Ctrl+F5.
I inputed 'e' and this is the output:
e C:\Peter\_CPP\hello\Debug\hello.exe (process 4808) exited with code 0. Press any key to close this window . . .
I pressed a key and the program exited.
Then I made a file called "h.txt" and went to Project->Properties->Configuration Properties->Debugging->Command Arguments
and used "<h.txt" for Command Arguments.
This time, when I pressed Ctrl+F5, a console appeared and immediately closed.
How can I solve this problem?
Thanks
Hi Yeeter,
Welcome to the MSDN forum.
If what you want is to add a .txt file to command arguments and use the data of it. I recommend you just type "test.txt" instead of "<test.txt".
Meanwhile, you can follow the following steps to get the data by command arguments.
- right click the project in solution explorer, choose add a new item, choose TextFile(.txt) and name it test.txt. Write some data in it like this: para1 para2 3 4 5 6 7 8 9...
- type "test.txt" instead of "<test.txt" in command arguments.
- write the code like below:
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main(int argc, char* argv[]) {
//get the data
fstream f;
f.open(argv[1]);
string line;
getline(f, line);
cout <<"content is:"<< line << endl;
//use this way to get every item of the data
string str1, str2, str3;
std::istringstream is(line);
is >> str1 >> str2 >> str3;
cout << str1 << "," << str2 << "," << str3 << endl;
//prevent the window from disappearing
system("pause");
return 0;
}
In this way, you can use the data of txt file to satisfy your need.
Best regards,
Sara
这篇关于Visual Studio社区2017 C ++启动而不调试不使用命令参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!