Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Piping input into a c++ program to debug in Visual Studio

this has probably been asked before, but I haven't been able to find any answers so far. I'm trying to start my program up with multi-line input, I.E. something I don't want to type in the command line every time (as I'd probably make a mistake). I looked into the command line arguments and I pasted my input in there, but it interpreted it as every line being a command.

Input in case it helps:

8
c j i b s x k j
t a o a v y z l
x r t s w o n m
z y x e n s p r
l l o b s t e r
t g x a a a a a
j p e l a k e k
t r s l j e e e
cat
test
baseball
bake
paste
lobster
stake
zen
locks
rake
gel
slack
jar
dinosaur
0
like image 402
Caleb Jares Avatar asked Mar 08 '12 04:03

Caleb Jares


People also ask

How do you Debug C code in Visual code?

message, choose the Install more tools and features link. Then, in the Visual Studio Installer, choose the Desktop development with C++ workload. In the Configure your new project window, type or enter get-started-debugging in the Project name box. Then, choose Create.

How do I Debug code in Visual Studio line by line?

Run to a breakpoint in code You can also select the line and then select F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert Breakpoint. The breakpoint appears as a red dot in the left margin next to the line of code. The debugger suspends execution just before the line runs.


1 Answers

Put your data in a file then go to the project properties in Visual Studio and select the "Debugging" category.

In the "Command Arguments" property type:

< "path/to/the/file"

Now that file will be fed to the program via standard input when the debugger is launched or when you launch the program within Visual Studio (but without the debugger) using Ctrl-F5.

You can use VS macros to specify the project directory, etc. if you want the test file to move along with the project.

like image 100
Michael Burr Avatar answered Oct 11 '22 09:10

Michael Burr