C++ string write to file problem.

hi guys, i am an extreme extreme extreme beginner to c++. im trying to get my program to create a file with my own extension and write data to it, but i keep getting the error; "cannot add two pointers' in line 17

please can you check my code, and identify my problem;

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
// write to file program.

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

using namespace std;

int main()
{
	cout << "Enter your name" << endl;
	
	char name[100];
	cin.getline(name, 100);

	char fxt[6] = ".XDT";
	char fname[106] = name + fxt;

	ofstream outfile;
	outfile.open(fname);

	outfile << name << endl;

	outfile.close();
	return 0;
}


thx a lot guys.
Last edited on
Don't say can't since it's technically possible. It would require concepts the OP is probably not familiar with yet and redundant coding of something better implemented elsewhere. But yes, the links given will help with a solution.
Don't say can't since it's technically possible.
possible to add arrays with +? how?
operator overloading
operator overloading
any other way? overloading operator is like making a function right? then i prefer using the standard library.
To be clearer, entire arrays can't be passed by value. Yet, the code isn't trying to do that either, as shown by the error cannot add two pointers. Just saying it can't be done is like telling the string class it can't do what it does. Impossible? no. Requiring an overly convoluted process that isn't usually necessary? Yes.
You can't overload operators for non user-defined types ( eg classes )
You never can use operators for arrays, you can use operator for classes defined to be similar to arrays (eg std::string)
Topic archived. No new replies allowed.