Having problems making a function (c++ netbeans 7.1)

  • From: "Miffiq" < >
  • To:
  • Subject: Having problems making a function (c++ netbeans 7.1)
  • Date: Tue, 26 Jun 2012 14:59:04 -0400

I am trying to make a void function that will create an empty file in the 
directory "files" in c++.  I also want to have the function automatically add 
the extention .DTBF to the file.  Here is some code I have written (it 
doesn't work.)


Code:

#include <cstdlib>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>

using namespace std;

void createFile(char* fileName){
    
    char* filePath = "files\\";
    char* fileExt = ".DTBF";
    char* completeFilePath = filePath + fileName + fileExt;
    
    ofstream createFile;
    createFile.open(completeFilePath);
    createFile.close();
    
}

int main{

printf("Creating the file...\n);
createFile("filename");
printf(Done.\n);

return 0;

}




Yes, I know I have a lot of includes.  I have spared you from seeing the 
other 400 lines of code that doesn't pertain to this function at all.  Also:  
I would prefer not to use the std::string or stringcpy etc. functions because 
a string doesn't work with the ofstream function.  If you have a workaround 
for this, please tell me.

The IDE tells me this on build:


"C:/Dev-Cpp/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= 
.build-conf
C:\Dev-Cpp\bin\make.exe[1]: Entering directory 
`C:/Users/Tusk/Documents/CodeRedRobotics/TestApp'
"C:/Dev-Cpp/bin/make.exe"  -f nbproject/Makefile-Debug.mk 
dist/Debug/MinGW-Windows/testapp__devcpp_.exe
C:\Dev-Cpp\bin\make.exe[2]: Entering directory 
`C:/Users/Tusk/Documents/CodeRedRobotics/TestApp'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe    -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o 
build/Debug/MinGW-Windows/main.o main.cpp
main.cpp: In function `void createFile(char*)':
main.cpp:44: error: invalid operands of types `char*' and `char*' to binary 
`operator+'
C:\Dev-Cpp\bin\make.exe[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
C:\Dev-Cpp\bin\make.exe[1]: *** [.build-conf] Error 2
C:\Dev-Cpp\bin\make.exe: *** [.build-impl] Error 2
C:\Dev-Cpp\bin\make.exe[2]: Leaving directory 
`C:/Users/Tusk/Documents/CodeRedRobotics/TestApp'
C:\Dev-Cpp\bin\make.exe[1]: Leaving directory 
`C:/Users/Tusk/Documents/CodeRedRobotics/TestApp'


BUILD FAILED (exit value 2, total time: 8s)


Thanks!






Having problems making a function (c++ netbeans 7.1)

Miffiq 06/26/2012

Having problems making a function (c++ netbeans 7.1)

MikeBoth 06/27/2012

Having problems making a function (c++ netbeans 7.1)

Miffiq 06/28/2012

Project Features

About this Project

CND was started in November 2009, is owned by Leonid Lenyashin, and has 130 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close