visual-c++

Reading file into array C++

时光毁灭记忆、已成空白 提交于 2021-01-29 18:18:12
问题 I am trying to simply read a file "input.txt" into an array people[]. The txt file has 3 numbers: 10 20 30 I am getting -9.25596e+61 instead of 10 for people[0]. Here is my code: #include <iostream> #include <string> #include <fstream> using namespace std; class Trip { private: double people[3]; public: void readFile(string file); }; void Trip::readFile(string file) { ifstream input; input.open(file); input >> people[0] >> people[1] >> people[2]; cout << people[0]; input.close(); } int main()

CPP - using * or & to return address

痴心易碎 提交于 2021-01-29 17:56:04
问题 I am writing a code to make a linked list. one of the function I wrote in order to make a linked list easier in the main function was[node is the name of a struct conatains a.data b.pointer name next) : node& create_node(int value) { node newitem; newitem.data=value; newitem.next=NULL; return (newitem); }; When I write the function like this everything is ok but I want to write the function header as : node * create_node(int value) But when I write it that way and I write return *newitem; I

Can you set Visual Studio 2017 CPU target for old CPU?

人盡茶涼 提交于 2021-01-29 14:18:22
问题 Is there a way to setup Visual Studio 2017 to support older CPU? Say one that doesn't have SSE2? Thanks. 回答1: You can select what CPU extensions to use (or not to use any) in the project's settings. The following works in VS2019 but, IIRC, it's very similar for VS2017. In the solution explorer, right-click on the project and select "Properties" from the pop-up menu. Open the C/C++ tree list and select the Code Generation page. Then, in the "Enable Enhanced Instruction Set" select the "No

SSE2 double multiplication slower than with standard multiplication

感情迁移 提交于 2021-01-29 09:42:28
问题 I'm wondering why the following code with SSE2 instructions performs the multiplication slower than the standard C++ implementation. Here is the code: m_win = (double*)_aligned_malloc(size*sizeof(double), 16); __m128d* pData = (__m128d*)input().data; __m128d* pWin = (__m128d*)m_win; __m128d* pOut = (__m128d*)m_output.data; __m128d tmp; int i=0; for(; i<m_size/2;i++) pOut[i] = _mm_mul_pd(pData[i], pWin[i]); The memory for m_output.data and input().data has been allocated with _aligned_malloc.

Function with auto parameter compiles using GCC but does not compile using Visual C++

谁说胖子不能爱 提交于 2021-01-29 09:16:59
问题 Please considere the following code-snippet: #include <iostream> void print(auto arg) { std::cout << arg << std::endl; } int main() { print("Hi"); return 0; } As you can see here (https://godbolt.org/z/2GSrXs) using GCC the code compiles and runs fine. As you can see here (https://godbolt.org/z/rtR6w9) using Visual C++ the code does not compile and results in the error message: <source>(3): error C3533: a parameter cannot have a type that contains 'auto' . It seems to me that this feature has

Function with auto parameter compiles using GCC but does not compile using Visual C++

别说谁变了你拦得住时间么 提交于 2021-01-29 09:08:06
问题 Please considere the following code-snippet: #include <iostream> void print(auto arg) { std::cout << arg << std::endl; } int main() { print("Hi"); return 0; } As you can see here (https://godbolt.org/z/2GSrXs) using GCC the code compiles and runs fine. As you can see here (https://godbolt.org/z/rtR6w9) using Visual C++ the code does not compile and results in the error message: <source>(3): error C3533: a parameter cannot have a type that contains 'auto' . It seems to me that this feature has

Ejecting CDRom Drive without hardcoding drive letter using Win32 Visual C++

早过忘川 提交于 2021-01-29 06:11:48
问题 I am trying to eject my CDRom Drive at the click of a button. This works when the CDRom drive letter is hardcoded, but I am wanting to do it without hardcoding the CDRom Drive. If I find the CDRom drive on my computer and save it to 'TCHAR drive_letter', how can I pull that in to the code below? For some reason, it does not allow me to do 'EjectCdTray(drive_letter);'. The code is shown below: #include <tchar.h> #include <windows.h> #include <mmsystem.h> // for MCI functions // Link to winmm

Microsoft C++ compiler have a bug?

断了今生、忘了曾经 提交于 2021-01-29 03:57:18
问题 usigned int x=1; signed int y = -1; double z = y * x * 0.25; I'm using Microsoft Visual Studio 10 C++ compiler. Why z don't have -0.25 value? As I saw from disassembly, it makes an signed int multiply (imul), places the result from edx on the stack, and extends it with 0!, as it would be an unsigned int. After that it multiplies it using FP instructions. ............. imul edx,dword ptr [ecx] mov dword ptr [ebp-98h],edx mov dword ptr [ebp-94h],0 fild dword ptr [ebp-98h] fmul qword ptr [__real

Microsoft C++ compiler have a bug?

好久不见. 提交于 2021-01-29 03:40:23
问题 usigned int x=1; signed int y = -1; double z = y * x * 0.25; I'm using Microsoft Visual Studio 10 C++ compiler. Why z don't have -0.25 value? As I saw from disassembly, it makes an signed int multiply (imul), places the result from edx on the stack, and extends it with 0!, as it would be an unsigned int. After that it multiplies it using FP instructions. ............. imul edx,dword ptr [ecx] mov dword ptr [ebp-98h],edx mov dword ptr [ebp-94h],0 fild dword ptr [ebp-98h] fmul qword ptr [__real

Google V8 - Neither v8.dll nor v8.dll.lib getting built in release mode

空扰寡人 提交于 2021-01-29 03:29:23
问题 I've followed the Building with GN instructions to build Google V8 on Windows 10 with Visual Studio 2015. What I did: Getting V8, after downloading and unpacking the depot-tools. C:\build-depot> set DEPOT_TOOLS_WIN_TOOLCHAIN=0 C:\build-depot> gclient C:\build-depot> set GYP_MSVS_VERSION=2015 C:\build-depot> fetch v8 Generating build files... C:\build-depot\v8> python tools\dev\v8gen.py x64.debug C:\build-depot\v8> python tools\dev\v8gen.py x64.release ... and compiling C:\build-depot\v8>