Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same OLD <iostream> Problem... or .Why does VC7 suck

Status
Not open for further replies.

slagathor

Technical User
Joined
Sep 13, 2003
Messages
5
Location
US
Why is it that even the simplest of the example programs from what is regarded as the BEST text on learning MFC (Richard Jones book) will even f***ing compile?

//Project: Ex01a_FirstLastReverse
// Illustrates various CString methods.
// Reverses names. From "George Washington"
// to "Washington, George"

#include <iostream.h>
#include <afxwin.h> // for CString

int main()
{
CString n; // for name
CString n1, n2; // first and last names
int nLen, n1Len, n2Len; // name lengths

n = &quot; George Washington &quot;;

cout << &quot;\n&quot; << n;

n.TrimLeft(); // remove preceeding spaces
n.TrimRight(); // remove spaces on right
nLen = n.GetLength(); // length of the name

int posBlnk = n.Find(&quot; &quot;); // get position of 1st &quot; &quot;

n1 = n.Left(posBlnk); // grab left portion of name
n1Len = n1.GetLength(); // length of first name

n2Len = nLen - n1Len;

n2 = n.Right (n2Len); // get right portion
n2.TrimLeft();

n = n2 +&quot;, &quot; + n1;
cout << &quot;\n&quot; << n;

cout <<&quot;\n&quot;;

return 0;
}

Compiling...
Main.cpp
c:\Documents and Settings\Brant Williams\My Documents\Visual Studio Projects\Intro to MFC Programming Assignments\Example Prog Code\Ch01_Part_1_UtilityClasses\Ex01a_FirstLastReverse\Main.cpp(6) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory


I still can't get a handle on header files, namespaces, etc etc. Please don't just answer this question by telling to &quot;add this..&quot; I want to understand what the heck is going on.

I have had more frustration trying to get simple Win 32 console programs (with MFC support) to compile that in writing much more involved, difficult programs.... HELP

 
Also note that if I change to <iostream> from <iostream.h> I now get the following:

Compiling...
Main.cpp
c:\Documents and Settings\Brant Williams\My Documents\Visual Studio Projects\Intro to MFC Programming Assignments\Example Prog Code\Ch01_Part_1_UtilityClasses\Ex01a_FirstLastReverse\Main.cpp(20) : error C2065: 'cout' : undeclared identifier
c:\Documents and Settings\Brant Williams\My Documents\Visual Studio Projects\Intro to MFC Programming Assignments\Example Prog Code\Ch01_Part_1_UtilityClasses\Ex01a_FirstLastReverse\Main.cpp(37) : error C3861: 'cout': identifier not found, even with argument-dependent lookup
c:\Documents and Settings\Brant Williams\My Documents\Visual Studio Projects\Intro to MFC Programming Assignments\Example Prog Code\Ch01_Part_1_UtilityClasses\Ex01a_FirstLastReverse\Main.cpp(39) : error C3861: 'cout': identifier not found, even with argument-dependent lookup


If I then add using namespace std, then I get:

Linking...
LINK : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
nafxcwd.lib(afxmem.obj) : error LNK2005: &quot;void * __cdecl operator new(unsigned int)&quot; (??2@YAPAXI@Z) already defined in libcpmtd.lib(newop.obj)
.\Debug/Ex01a_FirstLastReverse.exe : fatal error LNK1169: one or more multiply defined symbols found

 
Now here is a version that DOES work. The only problem is this is not the way to learn what the heck you are doing. I bought Jones' book because everyone said it was the only one that actually did not use the Wizards until you actually understood what the heck they did. This is accomplished by starting small, and builging from there. The problem is with VC++7 the only way to get the code to compile is to throw in a bunch of stuff I don't understand! This totally sucks.

Here is the program that works. Get a load of this:


***Test.cpp - This is the main *.cpp program file:***
// Test.cpp : Defines the entry point for the console application.
//

#include &quot;stdafx.h&quot;
#include &quot;Test.h&quot;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

//Project: Ex01a_FirstLastReverse
// Illustrates various CString methods.
// Reverses names. From &quot;George Washington&quot;
// to &quot;Washington, George&quot;

#include <iostream>
#include <afxwin.h> // for CString

using namespace std;


int main()
{
CString n; // for name
CString n1, n2; // first and last names
int nLen, n1Len, n2Len; // name lengths

n = &quot; George Washington &quot;;

cout << &quot;\n&quot; << n;

n.TrimLeft(); // remove preceeding spaces
n.TrimRight(); // remove spaces on right
nLen = n.GetLength(); // length of the name

int posBlnk = n.Find(&quot; &quot;); // get position of 1st &quot; &quot;

n1 = n.Left(posBlnk); // grab left portion of name
n1Len = n1.GetLength(); // length of first name

n2Len = nLen - n1Len;

n2 = n.Right (n2Len); // get right portion
n2.TrimLeft();

n = n2 +&quot;, &quot; + n1;
cout << &quot;\n&quot; << n;

cout <<&quot;\n&quot;;

return 0;
}





***stdafx.cpp - I have no problem with this....:***
// stdafx.cpp : source file that includes just the standard includes
// Test.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include &quot;stdafx.h&quot;

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file



***stdafx.h - until I see all this!....:***
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once


#include <iostream>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif

#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT


// TODO: reference additional headers your program requires here



***resource.h....and what is all this?....:***
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Test.rc
//

#define IDS_APP_TITLE 103

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif




***test.h...I can handle this....:***
#pragma once

#include &quot;resource.h&quot;




So how in the heck am I supposed to figure out what is going on with all this overkill. LOL!
 
Dear Mr Slagathor,

A word of advice. Don’t come in here slurring the tool. There are many members in this form that could take offense and decide to turn your denigrations on you.

You are not alone in finding C++ difficult to learn, regardless of the tool. Some people will get frustrated. The thing is, it’s not for everyone. If you are so deeply disturbed by it you might consider doing something else or even a different language like Pascal or Visual Basic.

>> what is regarded as the BEST text on learning MFC (Richard Jones book)

I don’t know that particular text so I can’t agree or disagree. One thing to consider is if the book was written to VC6 then you can expect some discrepancies with VC7, that however does not mean VC7 sucks. [lol] It just means you don’t’ know what you are doing and it does not help when you don’t have matching tools for your book.

C++ is complex enough that no text is going to make it easy to learn. Perhaps you would progress better in a tutoring environment. Try to find someone local that can give you some face to face time. A live person can explain concepts to you in minutes that otherwise could take weeks or months to grasp.

Senior C++ developers, mostly, have been around a while. That’s because it just takes time to learn. In my opinion, one certainly needs patience when starting down the C++ path.


-pete
 
change
#include <iostream.h>
...
cout <<...
...
cin >>...
...
to
#include <iostream>
using namespace std;
....
cout<<...
...
cin >>...
...
or
#include <iostream>
....
std::cout<<...
...
std::cin >>...
...

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Pablano...thanks for the advice. But I know that I don't know what I am doing! LOL! Thats why I ask. It is frustrating however, when you follow instructions and things still do not work. And then NO ONE can explain why....the texts all just scratch the surface or tell you to do something without telling you WHY. Just like most of the advice here. Thats why I took the time to post the code...and post the things I already tride that did not work....

For instance, I already tried all the things Ion suggested. No dice. Perhaps I need to go back to VC6. I think the structure of VC7 leads to a lot of problems. Just a suspicion....

I know that C++ is a big picture language...and lots of the details do not make sense until you have a lot of experience. It just seems the advice and instruction is too shallow to really figure out what is going on....

How in the heck are you supposed to learn when you copy the example code from a text exactly and it does not work??
 
>> How in the heck are you supposed to learn when you copy
>> the example code from a text exactly and it does not work??

Your expectations are not reasonable. Based on a few minutes of researching that book it appears it was written to VC6. As I stated before, the book does not know anything about VC7 so you can’t blame the book for that. Also you can’t blame VC7 for being different than VC6, if it was not different then why would it exist? Earth to slagathor… any body home? [lol]

If you seriously intend to continue programming in C++ you really need to think more logically than you appear to be doing in regards to this subject. I am not trying to be mean here, but at this point you actually are the problem. Stop cursing the books or tools. Be patient… think things through… take your time… and for goodness sakes either get the tool the book is meant for or expect problems to exist based on the differences.


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top