Hello ladies and gents,

I wanted to ask if any of you could help me out here, Ive got this program:

//Test programma voor Accelerated C++.

#include <fstream>
#include <iostream>
#include <string>

int main(int argc, char** argv)
{
	int fail_count = 0;
	//for each file in the input list
	for (int i = 1; i < argc; ++i)
	{
		std::ifstream in(argv[i]);

		//if it exists, write its contents, otherwise generate an error message
		if (in)
		{
			std::string s;
			while (getline(in, s))
				std::cout << s << std::endl;
		}
		else
		{
			std::cerr << "cannot open file " << argv[i] << std::endl;
			++fail_count;
		}
	}
	return fail_count;
}

The program should copy the content of any file that I give as arguments to main.

What I did is, I copied the Test.exe to my C harddrive, I then created a .txt file named Tekstfile and stored that also on my C harddrive.

I then use the cmd command and enter cd c:\
I then type Test and Tekstfile.

I thought this would make the program read what is written in Tekstfile and write this in Test, but, I'm getting the error message every time saying "cannot open file" , apparantly I'm doing something wrong :?:

Could any of you help me out, thanks.

Recommended Answers

All 2 Replies

If I understand correctly, you're doing this:

C:\>Test Tekstfile

Try this instead:

C:\>Test Tekstfile.txt

Hi Narue,


Yep, you understood it perfectly, thanks for the help ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.