write function on file

i am trying to write input() function into file.....
please help....
i am using visual studio 2013

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
  // N Copy.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "fstream"

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
	
	fstream file;
	file.open("NCopy.txt");
	file << input();
	file.close();
	system("pause");

	return 0;

	}

void input()
{
	cout << "Enter how many copies you want: ";
	int num;
	cin >> num;
	cout << "Enter text you want to copy: " << endl;
	char in[256];
	cin.getline(in, 256);
	for (int n = 1; n <= num; n++)
	{
		cout << n << ": " << in << endl;
	}
}
 
file << input();

This will print the value returned by input(), but the return type is void, meaning it doesn't return anything, so this will not work. You could make it work by changing the input() function so that it returns a string that you can write to the file. Or you could pass the file stream to the input() function and have it write directly to the file.
Topic archived. No new replies allowed.