Thread: Adding Strings/File Output

  1. #1
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    Adding Strings/File Output

    For the following code; if I enter 'filename' as the filename, shouldn't this pass 'filename.txt.' to the ofstream? There MUST be an easier way to do this.. plus the fact it doesn't work.

    Code:
    	char filename[24];
    	cout<<"Filename for data output (max 20 characters)->";
    	cin.getline(filename, 20, '\n');
    	filename[20] = '.';
    	filename[21]='t';
    	filename[22]='x';
    	filename[23]='t';
    	ofstream logfile(filename, ios::out | ios::end );
    	logfile.seekp(ios::end);
    Thanks.

  2. #2
    BubbleMan
    Guest

    Post Use this

    instead of using an array to add one char per array element(., t, x, t), try this:

    strcat(filename, ".txt");

    or:

    strcat(".txt", filename);

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Code:
    #include <apstring.h>
    
    	apstring apfilename;
    	cout<<"Filename for data output (max 20 characters)->";
    	cin>>apfilename;
    	apfilename += ".txt";
    	ofstream logfile(apfilename.c_str(), ios::out | ios::end );
    This is what I have now, exept I get no errors when compiling, but when I click 'Build .exe' I get:

    Code:
    --------------------Configuration: deviationcpp - Win32 Debug--------------------
    Linking...
    deviationcpp.obj : error LNK2001: unresolved external symbol "class ostream & __cdecl operator<<(class ostream &,class apstring const &)" (??6@YAAAVostream@@AAV0@ABVapstring@@@Z)
    deviationcpp.obj : error LNK2001: unresolved external symbol "public: char const * __thiscall apstring::c_str(void)const " (?c_str@apstring@@QBEPBDXZ)
    deviationcpp.obj : error LNK2001: unresolved external symbol "public: __thiscall apstring::~apstring(void)" (??1apstring@@QAE@XZ)
    deviationcpp.obj : error LNK2001: unresolved external symbol "public: class apstring const & __thiscall apstring::operator+=(class apstring const &)" (??Yapstring@@QAEABV0@ABV0@@Z)
    deviationcpp.obj : error LNK2001: unresolved external symbol "public: __thiscall apstring::apstring(char const *)" (??0apstring@@QAE@PBD@Z)
    deviationcpp.obj : error LNK2001: unresolved external symbol "class istream & __cdecl operator>>(class istream &,class apstring &)" (??5@YAAAVistream@@AAV0@AAVapstring@@@Z)
    deviationcpp.obj : error LNK2001: unresolved external symbol "public: __thiscall apstring::apstring(void)" (??0apstring@@QAE@XZ)
    Debug/deviationcpp.exe : fatal error LNK1120: 7 unresolved externals
    Error executing link.exe.
    
    deviationcpp.exe - 8 error(s), 0 warning(s)
    This is probably due to the ole32.lib file that came with apstring.cpp and apstring.h when I downloaded them, I don't know where to put it, I went to put it in VC98/Lib/ or something similar but it already existed, I'm sure this is what's causing the problem.
    Last edited by Dual-Catfish; 10-03-2001 at 07:24 PM.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    your compiler/linker can't file the apstring.h file. If you are sure it is with your compiler then try without the .h extension in the include.

  5. #5
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    No, It didn't come with my compiler, I had to download it (im using MSVC++ 6) I placed it in my directory with all the other .h files. Hmm.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    did you download a cpp or lib file to associate with the header file?

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    Apstring header file

    Hi. I'm still a beginner in C++ but i'm catching on kinda quickly. But what I want to know is why my apstring header file isn't working? My compiler (Dev-C++) didn't come w/ apstring.h, so I had to download from the internet. But it doesn't work.
    I receive the error " no match for `const char[8] << apstring &' " for my source file and " candidates are: class ostream & operator <<(ostream &, const apstring &) " for the apstring header file. Here's my source file that I made. Can you please help?

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


    int main()
    {
    apstring name, rank;
    char middle_initial;
    int years_of_service;

    cout<<"Enter the full name: ";
    getline(cin, name);
    cout<<"Enter the rank (Assistant, Associate, or Full): ";
    cin>>rank;
    cout<<"Enter the number of years of service: ";
    cin>>years_of_service;
    cout<<endl<<endl;
    cout<<"name: "<<name<<endl;
    cout<"Rank: "<<rank<<" Professor"<<endl;
    cout<<"Years of service: "<<years_of_service<<endl;
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  4. Adding output of a FOR loop
    By cjohnson412 in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2008, 07:41 PM
  5. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM