Having problems compiling my .cpp file on a linux machine

For some reason my code is not compiling on a linux server. It gives me several ofstream, ifstream, and fstream errors. It compiles perfectly fine on a windows machine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <fstream>
#include <string>

bool fileExists(const std::string);

//Bool function to test if output file already exists
bool fileExists(const std::string fileName)
{
	std::ifstream infile(fileName);
	return infile.good();
}


int main()
{
	std::ifstream file_in;//declares the input file
	std::ofstream file_out;//declares the output file
	std::string filename_in, filename_out;//declares the file strings
	
	//Name prompt for input file
	std::cout<<"What is the name of the input file?\n";
	std::cin>>filename_in;

	//Opens the input file
	file_in.open(filename_in, std::ios::in);

	//Error if input file fails
	if(file_in.fail())
	{
		//Gives error message and aborts
		std::cout<<"\nThe filename "<<filename_in<<" could not be read.\n";
		std::cout<<"Possible errors include:\n";
		std::cout<<"A - The file-path was not found or\n";
		std::cout<<"B - The file does not exist.\n\n";
		std::system("pause");
		exit(1);
	}

	std::cout<<"What is the name of the output file?\n";
	std::cin>>filename_out;

	//Checks to see if a file already exists
	if(fileExists(filename_out))
	{
		//Gives error message and aborts
		std::cout<<"\nThe filename "<<filename_out<<" already exists!\n";
		std::cout<<"ABORTING FILE COPY!\n\n";
		system("pause");
		exit(1);
	}

	//Opens the output file for writing
	file_out.open(filename_out, std::ios::out);

	//Loop that reads input and writes to output file
	char inp;
	while(!file_in.eof())
	{
		//reads the input char
		file_in.get(inp);
		//does not read eof char on last loop
		if(!file_in.eof())
		{
			file_out<<inp;
		}
	}

	//closes files
	file_in.close();
	file_out.close();

	std::cout<<"\nCopy Successful!\n";//Success message

	return 0;
}
http://www.cplusplus.com/forum/articles/40071/#msg216270

Unrelated
1
2
while( file_in.get(inp) )
   file_out << inp;
Linux machines tipically comes only with C compilers installed by default, are you sure g++ and libstdc++ are installed ?

Also std::system("pause"); obviously will only work on windows, unless there is a binary 'pause' in $PATH.
Last edited on
Hi,

Please show us the errors your getting, any compile or linkage errors.

Cheers,
Topic archived. No new replies allowed.