i got this error while debuging any program in c++ visual studio: cannot open source file iostream c++ visual studio an example is this program
#include <iostream>
using namespace std;
int main()
{
int test;
std:cout << "test" << "\n";
if(test = 1){
std:cout << "test well done" << "\n";
}
system("pause");
return 0;
}
how should i get the source file do i have to download it i never used vs code so i dont know
if anynone knows please help me thanks
I have a problem when i try to use function from my dll
I did everything as it says here:
https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019
But when i'm trying to run the test app, i get the following error messages:
Here is my whole code:
test.cpp:
#include "pch.h"
#include <iostream>
#include "SP_DLL.h"
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
int main()
{
symbol_count();
}
dlltest.h:
#pragma once
#include <iostream>
using namespace std;
extern "C" _declspec(dllexport) bool symbol_count();
dlltest.cpp:
#include "pch.h"
#include "SP_DLL.h"
bool symbol_count()
{
char str[100];
char symbol;
size_t count = 0;
cout << "Enter string: ";
cin >> str;
cout << endl << "Enter symbol to count: ";
cin >> symbol;
for each (auto el in str)
if (el = symbol) count++;
return true;
}
If it helps: when i'm trying to run empty symbol_count() (func have only code {return true;} and dll have no includes) there is the only one .dll not found.
I suggestyou could try to downloaded the installed packages from C++ Runtime v14 framework package for Desktop Bridge (Project Centennial),which provided the "msvcp140_app.dll". And then copied "msvcp140_app.dll" from the "C:\ProgramFiles\WindowsApps\Microsoft.VCLibs.140.00____8wekyb3d8bbwe " directory, placed it into your project folder.
– Jeaninez - MSFT Nov 8 at 2:25
this is my code i am using vs2013. i have set dependencies and all the linkers but still my code compiles correctly but when cosole opens it says error initializing vm, unable to find native libraries
#include <iostream>
#include <voce.h>
#include <Windows.h>
#include <string>
#pragma comment(lib, "jvm.lib")
#pragma comment(lib, "jawt.lib")
using namespace std;
int main()
{
init("C:\\voce-0.9.1\\lib\\", false, true, "C:\\voce - 0.9.1\\lib\\gram", "digits.gram");`
string s;
// Speech recognition in C++
while (voce::getRecognizerQueueSize() > 0)
{
s = voce::popRecognizedString();
cout << "You said: " << s << endl;
}
return 0;
}
I am starting with C++ (Visual Studio 2015 and Windows 8.1), with this simple code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world" << endl;
return 0;
}
But, the output screen shows nothing!, what shall I do?
Thanks in advance.
In Visual Studio, start the program with Ctrl-F5 and it will run and pause automagically for you. No additional code needed.
Your code is perfectly fine but the program currently only prints and exits right after, because this can happen very fast you might not be able to even see it,try pausing it :
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world" << endl;
cin.get();
return 0;
}
Also, make sure your Anti Virus isn't blocking Visual Studio.
Your code is just fine, however, if you execute it as a cmd program, the program window will close immediately, you might not be able to even see the output. You can write extra code to solve this problem by "pausing" the program:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
cout << "Hello world" << endl;
system("PAUSE");
return 0;
}
if you don't like include a windows.h file every time you type, you can add a "cin.get();" in the end of the code. But to be honest, since you are just a beginner, the coolest way I think you should try, is not to use Visual Studio to learn C/C++ but to install CodeBlocks(a simple but effective IDE) to write some codes that are not so long. You know, VS is for huge and complex projects and some practical program developing.
Another solution, platform dependent. My answer is for those of you who just need test pause for debugging purposes. It's not recommended release solution!
windows
#include <iostream>
int main()
{
std::cout << "Hello world" << endl;
system("pause");
return 0;
}
linux (and many alternatives)
#include <iostream>
int main()
{
std::cout << "Hello world" << endl;
system("read -rsp $'Press enter to continue...\n'");
return 0;
}
Detecting paltform
I used to do this on programming homework assignments, ensuring this only happens on windows:
#include <iostream>
int main()
{
std::cout << "Hello world" << endl;
#ifdef _WIN32
system("pause");
return 0;
}
Here's a good cheatsheet for ifdef macros and operating systems: http://sourceforge.net/p/predef/wiki/OperatingSystems/
The program exits on return 0; and window closes. Before this, you must pause the program. E.g you can wait for an input.
Here is a snippet from my code to do this. It works in both windows and linux.
#include <iostream>
using std::cout;
using std::cin;
// Clear and pause methods
#ifdef _WIN32
// For windows
void waitForAnyKey() {
system("pause");
}
#elif __linux__
// For linux
void waitForAnyKey() {
cout << "Press any key to continue...";
system("read -s -N 1"); // Continues when pressed a key like windows
}
#endif
int main() {
cout << "Hello World!\n";
waitForAnyKey();
return 0;
}
Just started a beginner c++ tutorial which eclipse is used. I am using a mac, so when creating a new project i chose the toolchain 'macxxx" something. In the video a different one is used because it is done in windows.
I tried running this super easy program :
#include <iostream>
using namespace std;
int main() {
cout <<'C++ is FUN'\n;
return 0;
}
When i click on the hammer to build it, I just get 3 errors :
Symbol 'cout' could not be resolved firstprogram.cpp Semantic Error
all similar to that.
How can i fix that ?
Does following code produce errors aswell?
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!";
}
You can end current line with << endl after "Some text to display". So it would look like
cout << "hello there " << endl;