tags:

views:

544

answers:

3
+1  Q: 

STDIN in Netbeans

Hi
Does someone know.. how to read files to STDIN in Netbeans.
I have a Problem my Program in Netbeans. The Program works like this :

./myprog < in.txt

It's a C++ Project. Any Ideas ?

Edit : I have Proglems with setting up netbeans . where can i say : READ/USE THIS FILE ? On the Console it just works fine !

A: 

Do you have access to the normal standard library classes in the NetBeans IDE? If so, normally you access STDIN using the cin instance:

std::string line;
while (std::getline(cin, line))
{
  // do something with line...
}
1800 INFORMATION
A: 

As far as I know, Netbeans is only an IDE, and it can be configured to use some different compilers. Your code should be coded according to what that compiler expects, but if you use the standard library you shouldn't have any problems.

Artur Soler
+1  A: 

I don't believe there's a way to ask NetBeans to pipe input to your program (that functionality is handled by your shell). If you want to test or debug your program in the IDE, the best way is to allow it to take a filename as a parameter, or fall back on standard input if no filename is given. Then you can adjust your project run configuration and supply the test filename as an argument.

Note that if you try to use "< file" in the run configuration, that will simply be passed directly to your program, because there is no shell intercepting it.

[Edit] I found a way, though it's a bit weak.

NetBeans (at least on my Mac) runs C++ programs via a script called dorun.sh, which is under the .netbeans folder in my home directory. It includes a line near the end like this:

"$pgm" "$@"

The quotes escape any use of the < operator in your project properties, so you could remove the quotes (and accept the consequences), or include a < between them:

"$pgm" < "$@"

and simply include the filename as an argument.

If you don't know where to find the arguments, it's in the project properties, off the file menu.

If you're using NetBeans on Windows, I'm not sure what kind of script (if any) it uses to launch your program. Also note that this doesn't work if you use the output window instead of an external terminal (this setting is in the same window).

[Edit edit] This is also no good when trying to debug your program... probably best just to amend your code to deal with reading from either a file or stdin.

JimG