Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3021

Newbie needs help

$
0
0
Hi,

First let me say think you in advance to anybody who is willing to take the time to help me out.

I am a VB6 guy from way back but trying to update my programming skills. Rather than tackle vb.net I thought I would try C++. I'm working with Visual C++ 2008.

It's been going pretty well for being only a few days into it but I have run into a difficulty. It's probably a very simple thing for experience programmers but C++ is great divergence from VB6 and I'm a little stuck.

My goal is to output a simple log file. I thought this would work best via a source (cpp) file as opposed to rewriting it for every form. I have created the .h header file and the .cpp file but can't seem to make it work. I've rewritten it 50 times at this point and google searched and dug threw my book but can't seem to figure it out.

I will throw some code out here but I know it's messed up and incomplete so please consider it a starting point.

Here is my CPPLog.cpp source file: (what do I actually need to #include and where and how do I need to innitialize the string?)

#include "stdafx.h"
#include "CPPLog.h"
#include <iostream>
#include <string>
using namespace System::IO;
using namespace System;

String ^ sLog;

void pLogWriter(String ^ sLog){
StreamWriter^ LogFile = gcnew StreamWriter("LogFile.txt");
LogFile->WriteLine(sLog);
LogFile->Close();
}


Here is my CPPLog.h header file: (I get an error saying invalid use of void. I read on some web site you can simply use the keyword string in the declaration but don't know if this is correct.)

#ifndef CPPLOG_H
#define CPPLOG_H

void pLogWriter(string);

#endif


Here is my calling function, or is it method, from main:

#include "CPPLog.h"

pLogWriter("Test");

Thanks again for your help, I greatly appreciate it.

Viewing all articles
Browse latest Browse all 3021

Trending Articles