Hi,
I need to convert the cpp code that I wrote in visual studio 2010 to visual C++ 6.0. However, I am getting errors.
I need to do this as I am designing some sequence for MRI scanner and siemens has only visual C++ 6.0 on the scanner.
I need to do very simple operations. I need to change directory and read two values from .txt file and convert it as double.
Also, it has to run on window as well as linux system as scanner uses both.
#include "stdafx.h"
//#include "test.h"
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
#ifdef WIN32
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
int main()
{
string STRING;
ifstream infile;
//Finding out the directory
char* pwd;
// Get the current working directory:
if( (pwd = _getcwd( NULL, 0 )) == NULL )
perror( "_getcwd error" );
else
{
printf( "%s \nLength: %d\n", pwd, strlen(pwd) );
}
//Conversion from char* to string
std::string PWD(pwd);
//printf ("The current working directory is %s", buffer);
string Filename = PWD + '/' + "example.txt";
infile.open (Filename);
cout<<"Verifying that cout works"<<endl;
while(!infile.eof()) // To get you all the lines.
{
cout<<"works fine here 1"<<endl;
getline(infile,STRING); // Saves the line in STRING.
cout<<"works fine here 2"<<endl;
cout<<STRING<<endl; // Prints our STRING.
}
infile.close();
Get_PWD();
system ("pause");
free(pwd);
return 0;
}
I was suggested by a friend to replace
#include "stdafx.h"
by
#include WIN32_LEAN_AND_MEAN
#include <winsock2.h>
Now, I am getting a single error.
error C2664: 'open': cannot convert parameter 1 from 'class _STL::basic_strring<char, class _STL::char_traits<char>, class _STL::allocator<char>>' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator can not be called.