Click to See Complete Forum and Search --> : 2 Questions
Technocrat
Oct 6th, 2000, 12:58 PM
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.
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
Vlatko
Oct 6th, 2000, 01:24 PM
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".
Technocrat
Oct 6th, 2000, 01:57 PM
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.
parksie
Oct 6th, 2000, 03:59 PM
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:
#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.
Technocrat
Oct 6th, 2000, 04:36 PM
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:
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
parksie
Oct 6th, 2000, 05:01 PM
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:
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!)
Technocrat
Oct 6th, 2000, 05:09 PM
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.
parksie
Oct 6th, 2000, 05:15 PM
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 :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.