I couldn't get in here for a while, my pc was clocking-busy place?!
I posted my problem to the wrong forum & didn't get any help-surprise!

I just want to know what I'm doing wrong in my code. I can't get rid of the 2 errors or understand what they mean. I'm a beginner. thx for any help!

//addrfile.cpp

#include <iostream.h>
#include "apstring.h"
#include <fstream.h>

int main()
{
    apstring user_name;
    int street_num;
    apstring street_name;
    apstring apt_num;
    apstring city;
    apstring state;
    int zip;

    ofstream outfile;
    ifstream infile;

    outfile.open("ADDR.DAT", ios::out);

    cout <<"Enter your name: ";
    getline(cin, user_name);
    cout << "Enter your street number: ";
    cin >> street_num;
    cout << "Enter your street name: ";
    getline(cin, street_name);
    cout << "Enter your apartment or hit enter if none: ";
    cin >> apt_num;
    cout << "Enter your City: ";
    getline(cin, city);
    cout << "Enter your 2 digit state code: ";
    getline(cin, state);
    cout << "Enter your zip code: ";
    cin >> zip;


    {
    outfile << "Name: " << user_name << endl;
    outfile << "Address: " << street_num, street_name << endl;
    outfile << apt_num << endl;
    outfile << city, state, zip << endl;
    }
    outfile.close();

    return 0;
}
--------------------Configuration: addrfile - Win32 Debug--------------------
Compiling...
addrfile.cpp
C:\C++ Files\Chapter 08\addrfile.cpp(39) : error C2678: binary '<<' : no operator defined which takes a left-hand operand of type 'class apstring' (or there is no acceptable conversion)
C:\C++ Files\Chapter 08\addrfile.cpp(41) : error C2297: '<<' : illegal, right operand has type 'class ostream &(__cdecl *)(class ostream &)'
Error executing cl.exe.

addrfile.obj - 2 error(s), 0 warning(s)

what`s in the header file
"apstring.h"
i think it`s creating the problem

First of using non-standard headers for this is totally not necesarry. Second spaces in your code make life much nicer :). Third I rewrote your program using standard headers and it works I made comments throughout showing what is going on.

#include <iostream>
//#include "apstring.h" This is a non standard header no need to use it
#include <string>// This is the header your looking for
#include <fstream>

using namespace std;//To comply with the standard by putting everything in namespace std

int main(void)
{
  
  string user_name;//notice we use string instead of apstring
  int street_num;
  string street_name; 
  string apt_num;
  string city;
  string state;
  int zip;
  bool isAptNum = true;//added a new variable to see if the have an apt_num or not

  ofstream outfile;
  //ifstream infile; werent using this

  outfile.open("ADDR.DAT", ios::out);

  cout <<"Enter your name: ";
  getline(cin, user_name);

  cout << "Enter your street number: ";
  cin >> street_num;
  cin.ignore(80,'\n');//this is so that it won't skip over your getlines because
  //there is still a '\r'(enter) in the stream 
  
  cout << "Enter your street name: ";
  getline(cin, street_name);
  
  //changed this you just can't hit enter for this it has to read in data
  cout << "Enter your apartment or enter none if none: ";
  cin >> apt_num;
  cin.ignore(80,'\n');
  
  if(apt_num == "none")
  {
    
    isAptNum = false;
    
  }    
  
  cout << "Enter your City: ";
  getline(cin, city);
  
  cout << "Enter your 2 digit state code: ";
  getline(cin, state);
  
  cout << "Enter your zip code: ";
  cin >> zip;
  cin.ignore(80,'\n');

  outfile << "Name: " << user_name << endl;
  outfile << "Address: " << street_num << " " << street_name << endl;
  
  if(isAptNum)//won't print to file unless they have a apt_num
  {
                                 
    outfile << apt_num << endl;
    
  }  
  outfile <<"City: " << city << endl;
  outfile <<"State: " << state << endl;
  outfile <<"Zip: " << zip << endl;
  outfile.close();

  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.