Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am making a program in C++, in which a web link is there so that when i type an input or simply press enter it will redirect me to that link which i have entered.
For example if i have 3 options and i choose option A, the program will redirect me to that link which is in the option A.
Here's a sample:-
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
system("COLOR B1");
int choice;
cout << "Menu" << endl;
cout << "1. Pasta" << "\n";
cout << "2. Cold Drink" << "\n";
cout << "Your choice (1-2)" << "\n";
cin >> choice;
if(choice == 1)
{
cout << "Thanks" << "\n"; //Here i want a url and when i choose 1 it
//will direct me to that url
}
else if(choice == 2)
{
cout << "Thanks" << "\n"; // And here also...
}
else
{
return 0;
}
}
Please help.
Thanks
In Windows desktop programs you can use the ShellExecute API with the open operation to open a URL with the default application (generally a web browser).
ShellExecute(NULL, L"open", L"https://example.com", nullptr, nullptr, SW_SHOWNORMAL);
Store apps can not use ShellExecute at all, but you can use the UWP LaunchUriAsync.
task = Windows::System::Launcher::LaunchUriAsync(
ref new Windows::Foundation::Uri("https://example.com"));
The various other platforms often have their own API's. In general you want to find and use them and not to assume any particular browser executable is on the path preventing users from using another or installing to a non-default location (or getting broken by updates, etc.).
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I would like to know How to make a console application close automatically after command in C++?
I want my program to ask "1) continue 2) Exit" and obviously proceed with the selected choice.
This is what I got so far:
#include <iostream>
int main() {
int choice;
std::cout << "1) continue 2) Exit. \n\n";
std::cout << std::endl;
std::cin >> choice;
std::cout << std::endl;
if (choice == 1) {
std::cout << " choice 1 selected, let's continue!";
}
if (choice != 1) {
//then close automatically?
}
}
If you really want to shut your window automatically when debugging stops,
"To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops."
Edit:
I forgot to mention that this is for Visual Studio 2019, Community Edition.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Beginner here so I'm sorry if I made nooby mistakes
I assign di to be the array myworld[] depending the the user input it'll assign the di into the appropriate array position, but for some reason the if statement keep outputting "make" instead of "change" when my input is 'c'
I tried to remove else if and put if for all of them, or got rid of else if and just use else.
#include <iostream>
using namespace std;
int main() {
char di;
char myword[] = {'d','m','s' ,'c'};
do {
cout << "Make a selection:" << endl;
cout << "d - insert 1$ bill" << endl;
cout << "m - view menu" << endl;
cout << "s - select an item" << endl;
cout << "c - get change" << endl;
cin >> di;
if (di == 'd')
di = myword[0];
else if (di == 'c')
di = myword[3];
}while (!myword);
if (myword[0])
cout << "make";
else if (myword[3])
cout << "change";
return 0;
}
Probably you forgot to make a comparison inside if statement. For now you are just saying if('d'!= 0) which is always true. Perhaps you tried to make if(di == myword[0]). The same applies for the else if statement.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
i am new in c++, i am working on a project, in case 1 i need to ask a file name from a user and if the file name is correct to it should print something like 6x5 character Array. I am totally confused that how to start. any single help will be appreciated.
#include <iostream>
using namespace std;
int main(){
int x;
string file;
int temp;
cout << "Welcome to Urban Heat Island Model" << endl;
cout << "What would you like to do? " << endl;
cout << "1. Load land cover file " << endl;
cout << "2. Model Temperature Based on land cover" << endl;
cout << "3. Exit " << endl;
cin >> x;
switch (x){
case 1:
cout << "What is the name of the file to import? " << endl;
cin >> file;
break;
If there is a file that you want to open, you can try a file stream. Here is a good look at how to open a file for input and output. Just make sure to check if you can actually open the file before you try to read/write from/to it. You can do it with
if(inputFile.is_open())
{
//your code here
}
If you just want to see if it is a valid file extension, check the last part of the string. If you have a list of file names, compare what they input and what you have to see if they are the same.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm making a program in C++ and did some experimenting. I included the system('pause') function. Now obviously I cannot close the program. How do I undo it and quit the program? Do I really need to restart my PC?
Basically I pranked my self. Here is the src code
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char answer;
cout << "Can gh0st be VIP?:(y=Yes/n=No)";
cout << endl;
cin >> answer;
if (answer == 'y')
{
cout << "thanx ande =)";
cout << endl;
}
else if (answer == 'n')
{
cout << "time to pay ande ahaha!\a\a\a\a\a\a\a...*with at least 200 more of these*";
cout << endl;
}
else
cout << "just put the letter y or n lol try it again";
cout << endl;
system("pause");
return 0;
}
Press "ENTER". .
Instead of doing system("pause") I would encourage doing a
cin.ignore();
cin.get();
This is a longer form of pause that I have found is very easy to use. And also you just hit the little red square close to the help menu.
pause is not part of C or C++, this is a command from Windows Command Prompt, which is called using the system() syscall.
Once system() is called, your thread hangs at that point until whatever program or command you call with system() is concluded and returns the exit code.
pause is a shell command that will wait for any key to be pressed by the user. Any key pressed will interrupt pause and your program will continue.
Just make sure the key you press is NOT the reset button.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i need in my loop get character in realtime and check it by conditions. If user press whatever except enter, program works fine. Can anyone help me ? thanks !
while (read != '\n')
{
cout << "Enter character:\n";
read = _getwch();
if (read == '\n') {
cout << "You pressed : ENTER\n";
}
else {
cout << "Your character is: \"" << read << "\"\n\n";
read = '\0';
}
}
include
using namespace std;
int main()
{
cout << "Press the ENTER key";
if (cin.get() == '\n')
{
cout << "Good job.\n";
}
else
{
cout << "I meant ONLY the ENTER key... Oh well.\n";
}
return 0;
}
This code will help in detecting the ENTER key when pressed.
Hope this helps you.