Question

I have a C++ program not reading an absolute path in Visual Studio.

The following code works on my desktop environment (Windows 7, Visual Studio 2010, 64 bit). However, on my macbook, I am running bootcamp and/or VMware for a Windows 7 64 bit virtual machine that has the exact same Visual Studio 2010.

My attempts at fixing this problem:

  1. I made sure that the absolute path is the same on my macbook as it is on the desktop. I further made double sure that I installed the third party library to read my wave file in the same fashion as I did for the desktop twice.

  2. I rewrote the program that run on the desktop, reinstalled the library on my macbook. Simpler program works on desktop, but alas, still failed to read absolute path on macbook.

  3. I moved the wav file so not to be a path, but in the actual project solution itself. No change.

  4. Google.

I include the code at the bottom, for your benefit. I used libsndfile library to read a wav file. I may just try to use my very old crappy Windows laptop, but would can't understand what could be going wrong on my macbook VM machine.

// WaveReader.cpp : main project file.

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <sndfile.h>

using namespace System;

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    SNDFILE *sf; 
    SF_INFO info; 

    /*Open the wav file. */
    info.format = 0;
    sf = sf_open("C:\\Users\\geekyomega\\gameover.wav",SFM_READ,&info);
    if (sf == NULL)
    {
        printf("Failed to open the file.\n");
        getchar();
        exit(-1);
    }

}

My output, when I run this program is

Failed to open the file

As always, thank you for reading through this question. I deeply would appreciate any help, assistance, or wisdom any of you would have. Especially if you encountered a similar problem.

Warm Regards, GeekyOmega

Was it helpful?

Solution

It turned out to be related to permissions. Also, Hans Passant is right in that absolute paths are not good coding practice. This was meant as a proof of concept, so please let me off on that technicality.

Regards, GeekyOmega

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top