ifstream not working

Hey folks,

... in my first week of C++ programming, I'm using ubuntu and eclipse ide.

I can't get ifstream to read a simple text file. goo.txt is just a garbage file with some random alphabetic characters, and it is in the same folder as my project files. I included the getcwd to echo my current working path to assure that my file is in the same place as the code is being run... and it is. I have also tried full path "/home/user/.../goo.txt" as well to no avail, and there's not spaces, special characters, etc. in the path. File permission is RW for everyone. The only result I get from running this code is "incomplete type" for myReadFile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
#include <fstream>

using namespace std;


void GetCurrentPath(char* buffer)
{
getcwd(buffer, 100);
}

int main() {
	char CurrentPath[100];
	GetCurrentPath(CurrentPath);
	cout << CurrentPath << endl;

	ifstream myReadFile;
	myReadFile.open ("goo.txt");

	myReadFile.close();
	return 0;
}


what am I missing?

EDIT: "using namespace rapidxml;" removed... had cut down code, forgot to take out that line. problem remains, everything builds, i just reduced extra code for simplicity


EDIT2: Never mind, I'm an idiot... that's what it is supposed to do. I thought it would read in a character array or string or something to the value... did more reading, got it working.
Last edited on
The code as presented does not compile. rapidxml is not a recognised namespace.
Moschops, yes your right.. I had used a text editor to cut out some of my extra code related to loading an xml parser, and forgot to remove rapidxml namespace... the edited code snippet above compiles now, but still problem remains with not loading the .txt file

What does it say about this code? Which compiler (not IDE) are you using?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
#include <fstream>

using namespace std;


void GetCurrentPath(char* buffer)
{
getcwd(buffer, 100);
}

int main() {
	char CurrentPath[100];
	GetCurrentPath(CurrentPath);
	cout << CurrentPath << endl;

	ifstream myReadFile("goo.txt", ifstream::in);
	

	myReadFile.close();
	return 0;
}
Topic archived. No new replies allowed.