0

I am using Visual Studio and I want to run a simple program that uses cin to read input parameters

#include <iostream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    cout << n << k;
    return 0;
}

Now I want to run the program passing this two parameters. I usually run by pressing Ctrl+Alt+N or just right clicking and selecting Run but I don't see how can I input my parameters.

When I run, VisualStudio basically does:

cd "/home/user/codeforce/" && g++ 977A.cpp -o 977A && "/home/user/codeforce/"977A

Is there a way to input parameters so they are read by cin?

  • Does this answer your question? [debugging with visual studio using redirected standard input](https://stackoverflow.com/questions/14043986/debugging-with-visual-studio-using-redirected-standard-input) – Scheff's Cat Mar 31 '20 at 10:16

3 Answers3

0

Start from the top: Press CTRL + f5 to run the program. A prompt will ask you if you want to Save\Build the project. Click 'yes' to both. A console window will appear, and based on your code, it will just be blank with a flashing cursor waiting for you to enter your values for n and k. Keep in mind that your code will take values for both n and k at the same time if you have any spaces, so if you input

10 45

the output will be

1045
pctopgs
  • 439
  • 1
  • 4
  • 10
0

The default keyboard shortcut Ctrl + Alt + N in Visual Studio corresponds to TSqlEditorCloneQuery.

I suggest you could follow the following steps to build and run your code in Visual Studio:

1,To build your project, choose Build Solution from the Build menu. The Output window shows the results of the build process.

enter image description here

2,To run the code, on the menu bar, choose Debug, Start without debugging.

enter image description here

A console window opens and then runs your app. When you start a console app in Visual Studio, it runs your code, And then you could enter values for n and k.

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20
-1

Personally I do not use VisualStudio because it is very complicated compared to other editors, such as Atom or even command line editors such as vim. I did a quick research and found this.

Properties -> Debugging -> Command Arguments

LC05
  • 107
  • 1
  • 7
  • Command-line arguments are a different from streams, such as `std::cin`. Hence, your answer, doesn't, directly, answer the question, of "_Is there a way to input parameters so they are read by cin?_" – Algirdas Preidžius Mar 31 '20 at 10:15