Results 1 to 8 of 8

Thread: 2 Questions

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    First is there something in VC that is like app.path in VB?

    Second I am using the following code to read text from a text file. But my text file is multi lines with carraige returns. How do I make one varible with all the text in it.

    I know that this is the old way to do things but I want to learn the basics first.

    Code:
    	FILE *p_file;
    	char out[256];
    	char *p_out = out;
    
    	p_file = fopen(FileLoc , "r");
    
    	while (!feof(p_file))
    		{
    			fgets(out,sizeof(out),p_file);
    		}
    
    	fclose(p_file);
    Thanks
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    If you are making a console app then the argv[0] argument holds the app.path information.
    The C++ equivallent of vbCrLf(in VB) is "\r\n".
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I will try argv[0], but my program is a windows app without MFC

    I know that \r\n will do lines but I need to know is that in my example my VAR out will only contain one line on each pass how do I merge all the lines together. Like newout = newout & out in VB.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Firstly, I would suggest using the ifstream class. It supports taking lines from a text file, and performs all the necessary character translations for you ("\r\n" -> "\n", and others).
    Secondly, the string class will be very helpful here. For example:
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    void x() {
        ifstream MyFile("file.txt");
        char *pcBuf[1024];
        string sTemp;
    
        if(MyFile.fail()) {
            // could not open file
            return;
        }
    
        while(!MyFile.eof()) {
            MyFile.getLine(pcBuf, 1024);
            sTemp += pcBuf;
        }
    }
    ...or similar.

    Try using GetModuleFilename() with AfxGetApp() to get your path name.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Thanks parksie

    I have another question
    I made a SDI MFC project and I want the main window to be an edit box. If I use:

    Code:
    if (!m_wndView.Create("Edit", NULL, EDIT_STYLE,
    		CRect(0, 0, 0, 0), this,  AFX_IDW_PANE_FIRST, NULL))
    	{
    		TRACE0("Failed to create view window\n");
    		return -1;
    	}
    I cannot type in the window, but it has all the attibutes of an edit box. Any idea on how to make that work? Or a better way.

    Damn VC++ is hard compared to VB
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Hmm...can't think of a way at the moment.

    Although, C++ will always be harder than VB. At the moment, there are 5 generations of programming languages, getting harder towards 1:
    Code:
    1GL - Pure machine code (writing in a hex editor)
    2GL - Assembler
    3GL - C/C++
    4GL - VB, Delphi
    5GL - Prolog, SQL
    Java fits in at about 3.5 .
    Yes, C++ is harder, but it is a heck of a lot more powerful. You can do anything you'll ever need to in C++, and then some.

    (quick suggestion - if you're only learning C++, don't go straight into windows apps. Learn console mode first!)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Oh well thanks anyways
    I am sure I will figure it out sooner or later

    It's just angering when I am almost done making a better winamp that has all the features of winamp, fully skinable, etc in VB and in VC I can't even make a window with and edit box in it.

    I think I have a good console knowledge. I can do lots of the basic functions, except write and read of course.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You'll get over it.

    Although, for a much better learning experience (and a smaller program), use pure API (the Platform SDK has loads of info). It's not that difficult, and the rewards are fantastic
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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