Can't launch website in C++ - c++

Trying to launch a website in Visual C++ 2010 Express, every researched solution has not worked. So I gather I need more in-depth assistance. Here's my code:
#include <stdafx.h>
#include <stdio.h>
#include <iostream>
#include <io.h>
#include <string>
#include <string.h>
#include <conio.h>
#include <windows.h>
using namespace System;
using namespace std;
int main()
{
char name[240];
cout<<"\nHello, Please enter your name: ";
cin.getline(name,240);
cout<<"\nHello "<<name <<", your ID has been confirmed!";
cout<<"\nContinuing to launch website 'xyz' now.";
// system("C:\\Program%Files\\Google\\Chrome\\Application\\chrome.exe");
ShellExecute, TEXT("open"), TEXT(c:\\program
files\\google\\chrome\\application\\chrome.exe), NULL, NULL, SW_SHOWNORMAL;
goto end;
end:
cout<<"\n\nProgram completed, Pess any key to exit. ";
_getch();
return 0;
}

Like this.
ShellExecute(NULL, TEXT("open"), TEXT("c:\\program files\\google\\chrome\\application\\chrome.exe"), NULL, NULL, SW_SHOWNORMAL);
You had missing parens, missing double quotes and quite possibly spurious characters between 'program' and 'files' in your path. You also had a missing parameter to ShellExecute.
Reading a book and learning a minimum of C++ syntax would be a good idea. These are very basic errors.

system("\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" http://heise.de");
works for me.
See How to call an external program with parameters?

Related

What can I replace with the sleep command in the Windows variant of ncurses?

#include <curses.h>
#include <unistd.h>
#include <iostream>
int main() {
initscr();
mvaddstr(10, 10, "Hello, world");
refresh();
sleep(4);
endwin();
std::cout << "DONE\n";
}
I'm working on a project and I need to take down the curses windows for a while just to write a path to directory in cmd and then let the curses windows come back. I found this code on this site and tried to use sleep command in the code but it didn't work.
So if anyone knew how to solve this please write it down here. Thnx :)
napms is the (portable) curses function to use instead of sleep

Is there a way to play a sound without delay?

My program is playing a sound PlaySound.
The program works fine and I can hear the sound, but when the song end, there is a delay for like 1 second, and then the song play again.
I asked Google, and he gave me this question - PlaySound() Delay
The guy who answerd , said that instead SND_SYNC we need to use SND_ASYNC, I listened to him and did it, but I can't hear anything.
Do you have any suggestions ?
Btw, this is the song I'm currently using for this project - Nyan Cat
I want that this song will be start again immediately, for the user to not hear that there is a Delay.
Final Code:
#include <iostream>
#include <Windows.h>
#include <string>
#pragma comment(lib, "winmm.lib")
int main()
{
std::string pathtosound = "C:\\Users\\roile\\Documents\\Dragonite\\nyan.wav";
while (true) {
PlaySound(pathtosound.c_str(), 0, SND_SYNC);
}
return 0;
}
The SND_LOOP flag is described as follows in Microsoft Docs:
The sound plays repeatedly until PlaySound is called again with the
pszSound parameter set to NULL. If this flag is set, you must also set
the SND_ASYNC flag.
Pay attention to the last sentence, hence the following code will probably work better:
#include <iostream>
#include <Windows.h>
#include <string>
#pragma comment(lib, "winmm.lib")
int main()
{
std::string pathtosound = "C:\\Users\\roile\\Documents\\Dragonite\\nyan.wav";
PlaySound(pathtosound.c_str(), 0, SND_ASYNC | SND_LOOP);
while (true) {
// Stop loop at some point
}
PlaySound(NULL, 0, 0); // Stop sample
return 0;
}

Visual Studio 2015 OpenCV Assertion failed (size.width>0 && size.height>0) in cv::imshow windows.cpp

I've been learning a bit of c++ lately and i keep getting the same error for some reason.
Apparently, imshow isn't able to find the file.
My codes are
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include<iostream>
#include <conio.h>
using namespace std;
using namespace cv;
int main()
{
cv::Mat img;
img = imread("1.png");
if (img.empty())
{
cout << "can't find da file\n\n" ;
}
cv::namedWindow("test");
cv::imshow("test",img);
waitKey(0);
}
I've tried putting it in the project folder along with the ".exe",
I tried listing the whole directory of the image using "/" and "\"
I've also tried not using any extensions in the code but to no avail.
Error Signs
Thanks for helping you guys :)
I always advise the same thing for these cases. It just needs a little lateral thinking. Change your code to this
int main()
{
ofstream test("test.txt");
test << "I'm here!!\n";
}
Now run this program, it will create a file called test.txt. Find out where that file is on your system and that's where you should put your 1.png file. Then you can go back to your original program confident that the file is in the right place and any remaining issues are a different problem.

C++ Text-To-Speech undefined errors

#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#include <string.h>
#include <fstream>
char *sounds[] = {"d.wav","ai.wav","v.wav","i.wav"};
int main()
{
char input[20];
int k;
int i = 0;
std::cin >> input;
while (input[i])
{
k = input[i] - 'a';
PlaySound(TEXT(sounds[k]), NULL, SND_ASYNC);
}
system("pause");
}
In an attempt to make a text to speech program, I have come across this problem.
int k, reads the input and plays the .wav file connected with the string that is read. The problem arises from PlaySound(TEXT(sounds[k]), NULL, SND_ASYNC);. The errors read: (IntelliSense: identifier "Lsounds" is undefined) and (error C2065: 'Lsounds' : undeclared identifier). Which both seem to mean the same thing, however, I can not find the source of the problem or whats causing it. How was/is Lsounds undefined and how would I fix it?
It's TEXT(sounds[k]) that's causing the issue. TEXT() is a macro that expands to L followed by what you type inside, so that's the equivalent of Lsounds[k], hence the error.
The PlaySound API is used for playing WAVE files. You should use SAPI COM interface for TTS:
CComPtr <ISpVoice> cpVoice;
//Create a SAPI Voice
HRESULT hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
if(SUCCEEDED(hr))
{
cpVoice->Speak(L"Hello World", SPF_DEFAULT, NULL);
}

C++ Auto Format

I am trying to create a program that auto formats my f:\ (USB Drive), and I have this code so far:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream>
int main ()
{
system ("format f:");
system("pause");
return 0;
}
Now, when I run that, it comes up, with me needing to press Y, then Enter. How can I simulate that?
As Tyler said in a comment, a batch file would be much easier, but this might work:
system( "echo y | format f:" )