CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2014
    Posts
    3

    [RESOLVED] Newbie needs help

    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.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Newbie needs help

    If you're using .Net you need to ask in the managed C++ forum. You'll get a much better response if you use code tags to maintain formatting.

  3. #3
    Join Date
    Jul 2014
    Posts
    3

    Re: Newbie needs help

    Quote Originally Posted by GCDEF View Post
    If you're using .Net you need to ask in the managed C++ forum. You'll get a much better response if you use code tags to maintain formatting.
    Thank you GCDEF, I'll post it there!

    I'll look into the formatting. I appreciate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured