Results 1 to 11 of 11

Thread: how to make a tab in C++??

  1. #1
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944

    how to make a tab in C++??

    Thanks, i am looking through my damn book and cant find how
    .....

  2. #2
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944
    one more heh, how do u save ur Output to a file?

    I have a program which has too much info to display on a scrn

    thanks for looking
    .....

  3. #3
    SG DC Team Member Paft's Avatar
    Join Date
    Feb 2001
    Location
    Charlottesville, VA
    Posts
    5,736
    I believe that a tab character is \t. Something like this:

    Code:
    cout << "Hello\t World";
    To output to a file is just a LITTLE harder.. heh.. take a look at this and see if you can figure it out. If not, I can try to explain..

    Code:
    ofstream wfile("flatfile"); // Open file for output
    	if(!wfile) // If file fails to open
    	{
    		cerr << "File did not open correctly." << endl; // Output to standard error
    		return(1);
    	}
    	else
    	{
    		cout << "Input message: "; // Program code, not needed for file I/O
    		cin.getline(message, 1025, '\n');
    
    		crypt();
    
    		x = 0; // End program code
    
    		while(encrypt[x] != 0)
    		{
    			wfile << encrypt[x]; // This sends the data in the encrypt array to the file instead of Standard Output
    			wfile << "|"; // A delimiter
    			x++;
    		}
    	}
    	wfile.close(); // Close the file

  4. #4
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944
    awww now i remember from lecture, thanks alot paft
    .....

  5. #5
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944
    im confused is wfile a name i can switch with my own? what is that inside the quotes after wfile? where does the ofstream start?
    .....

  6. #6
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944
    //Benjamin Lee CSE123c Section-08 Fall 2003

    #include <iostream>
    #include <cmath>

    using namespace std;

    int main ()

    {
    double windc, //windchill
    winds, //windspeed
    temp;

    ofstream wfile("hw6.doc");
    if(!wfile)
    {
    cerr << "File did not open correctly." << endl;
    return (1);
    }
    else


    cout<<" Windchill Temperature"<<endl<<" ";

    for (temp=-35; temp<=35; temp+=5)
    {
    cout<<temp<<" ";

    }

    for (temp=-35; temp<=35; temp+=5)
    {
    cout<<" "<<temp;
    for (winds=5; winds<=60; winds+=5)
    {
    windc=35.74+0.6215*temp-35.75* pow(winds,0.16) + 0.4275 * temp * pow(winds,0.16);
    cout<<windc;
    }
    cout<<endl;



    }


    return 0;


    }



    --------------------Configuration: Homework 6 - Win32 Debug--------------------
    Compiling...
    Homework 6.cpp
    D:\C++\Homework 6.cpp(15) : error C2079: 'wfile' uses undefined class 'basic_ofstream<char,struct std::char_traits<char> >'
    D:\C++\Homework 6.cpp(15) : error C2440: 'initializing' : cannot convert from 'char [8]' to 'int'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    Error executing cl.exe.

    Homework 6.exe - 2 error(s), 0 warning(s)
    .....

  7. #7
    SG DC Team Member Paft's Avatar
    Join Date
    Feb 2001
    Location
    Charlottesville, VA
    Posts
    5,736
    Originally posted by aagiants
    im confused is wfile a name i can switch with my own? what is that inside the quotes after wfile? where does the ofstream start?
    wfile is the identifier I'm using to identify the file I want to write to. Yes, you can change it.

    The thing inside the quotes is the file I'm writing to. That could be anything.. xxx.bin for all the program cares.

    The ofstream is basically saying "open the file for editing". It's a function like cout.

  8. #8
    SG DC Team Member Paft's Avatar
    Join Date
    Feb 2001
    Location
    Charlottesville, VA
    Posts
    5,736
    Your code... You need to add the header <fstream.h> to it.

  9. #9
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944
    --------------------Configuration: Homework 6 - Win32 Debug--------------------
    Compiling...
    Homework 6.cpp
    D:\C++\Homework 6.cpp(16) : error C2872: 'ofstream' : ambiguous symbol
    D:\C++\Homework 6.cpp(19) : error C2872: 'cerr' : ambiguous symbol
    D:\C++\Homework 6.cpp(25) : error C2872: 'cout' : ambiguous symbol
    D:\C++\Homework 6.cpp(29) : error C2872: 'cout' : ambiguous symbol
    D:\C++\Homework 6.cpp(35) : error C2872: 'cout' : ambiguous symbol
    D:\C++\Homework 6.cpp(39) : error C2872: 'cout' : ambiguous symbol
    D:\C++\Homework 6.cpp(41) : error C2872: 'cout' : ambiguous symbol
    Error executing cl.exe.

    Homework 6.exe - 7 error(s), 0 warning(s)



    //Benjamin Lee CSE123c Section-08 Fall 2003

    #include <iostream>
    #include <fstream.h>
    #include <cmath>

    using namespace std;

    int main ()

    {
    double windc, //windchill
    winds, //windspeed
    temp;

    ofstream wfile("hw6.doc");
    if(!wfile)
    {
    cerr << "File did not open correctly." << endl;
    return (1);
    }
    else


    cout<<" Windchill Temperature"<<endl<<" ";

    for (temp=-35; temp<=35; temp+=5)
    {
    cout<<temp<<" ";

    }

    for (temp=-35; temp<=35; temp+=5)
    {
    cout<<" "<<temp;
    for (winds=5; winds<=60; winds+=5)
    {
    windc=35.74+0.6215*temp-35.75* pow(winds,0.16) + 0.4275 * temp * pow(winds,0.16);
    cout<<windc;
    }
    cout<<endl;



    }


    return 0;


    }
    .....

  10. #10
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944
    all fixed thanks
    .....

  11. #11
    Reigning Genious aagiants's Avatar
    Join Date
    Jan 2001
    Posts
    5,944
    edit
    .....

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •