text output almost works

This is a discussion on text output almost works within the C++ Programming forums, part of the General Programming Boards category; #include <stdlib.h> #include <iostream> #include <string> #include <fstream> #include <windows.h> using namespace std; int main() { ifstream fin; string szName ...

  1. #1
    Shadow12345
    Guest

    text output almost works

    #include <stdlib.h>
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <windows.h>
    using namespace std;

    int main()
    {

    ifstream fin;
    string szName = "";
    int health=0, gold = 0;

    fin.open("Stats.txt");
    if(fin.fail())
    {
    cout << "ERROR: Could not find .txt file!\n";
    return 0;
    }
    cout << endl;
    while(fin >> szWord)
    cout << szWord;
    }

    I get this error C:\outputprogram.cpp(22) : error C2065: 'szWord' : undeclared identifier

    how should i change it
    thanks in advanced

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    you haven't defined it. add a
    Code:
    string szWord;
    to the top of your code somewhere.

  3. #3
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    I dont get this, why is everybody putting sz before the variables?
    I've seen other people do this aswell.
    Is it some book that tells you to do this?!?

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> Is it some book that tells you to do this?!?

    Browse the Microsoft documentation. It is generally known as "Hungarian Notation". It is supposed to be useful in that you can see at a glance the type of a variable by the prefix letters.

    >>> why is everybody putting sz before

    Everybody isn't, some do.

    Frankly, I have never agreed with it, and the prefix's become so damn complicated that you spend minutes trying to work them out - I guess, however, it would come with practice.

    It may have had uses in the past, but any decent IDE these days will tell you what type a variable is, offer to take you to it's definition etc.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Shadow12345
    Guest
    why do all these damn people playing online games say 'all your base are belong to us' and why are tomatoes considered a fruit, and why we all have to ask so many questions?

  6. #6
    Registered User Invincible's Avatar
    Join Date
    Feb 2002
    Posts
    210
    Why do you want people to stop asking questions? :P
    "The mind, like a parachute, only functions when open."

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    cause they gain in posts!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. Input a Hex number and output hex number to a text field
    By zoobaby in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2009, 11:26 AM
  3. text output in text editor
    By realjag in forum C++ Programming
    Replies: 5
    Last Post: 10-29-2005, 06:51 PM
  4. Text output into other applications
    By melchior in forum C Programming
    Replies: 9
    Last Post: 09-21-2005, 01:40 AM
  5. mygets
    By Dave_Sinkula in forum C Programming
    Replies: 6
    Last Post: 03-23-2003, 06:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21