new help with string

This is a discussion on new help with string within the C++ Programming forums, part of the General Programming Boards category; [code] void getfilename (string,string&); void reformat (string); void writeinfo (ofstream&,string,string); int main() { cout<<fixed<<showpoint<<setprecision(2); ifstream input;//variable infile represents the name ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    3

    Question new help with string

    [code]
    void getfilename (string,string&);
    void reformat (string);
    void writeinfo (ofstream&,string,string);
    int main()

    {
    cout<<fixed<<showpoint<<setprecision(2);
    ifstream input;//variable infile represents the name of the file being opened
    ofstream output;//
    string out_putname="velazq32_taxes";
    string filename,lname,status;
    getfilename("input",filename);
    input.open(filename.c_str());
    output.open(out_putname.c_str());
    input >> lname;
    while (!input.eof())
    {
    input >> status;


    writeinfo(output,lname,status);
    reformat(lname);

    input >> lname;
    }
    input.close();

    output.close();
    return 0;
    }
    void writeinfo (ofstream& out,string lname,string status)
    {


    out << left <<"Tax summary for "<<lname<<" family"<<endl;
    out<< left<<"Filling status: "<<status<<endl;
    }
    void getfilename(string filetype,string& filename)
    {
    cout << "Enter name of " << filetype << " file\n";
    cin >> filename;
    }

    void reformat (string lname)

    //Given a word, convert the first letter to upper case and the
    //rest of the letters to lower case. The converted word will
    //be passed back.
    {
    int wlen;
    wlen = lname.length();
    lname[0] = toupper(lname[0]);
    for (int i=1; i<wlen; i++)
    lname[i] = tolower(lname[i]);
    }
    Code:
    void getfilename (string,string&);
    void reformat (string);
    void writeinfo (ofstream&,string,string);
    int main()
    
    {
    cout<<fixed<<showpoint<<setprecision(2);
    ifstream input;//variable infile represents the name of the file being opened
    ofstream output;//
    string out_putname="velazq32_taxes";
    string filename,lname,status;
    getfilename("input",filename);
    input.open(filename.c_str());
    output.open(out_putname.c_str());
    input >> lname;
    while (!input.eof())
    {
    input >> status;
    
    
    writeinfo(output,lname,status);
    reformat(lname);
    
    input >> lname;
    }
    input.close();
    
    output.close();
    return 0;
    }
    void writeinfo (ofstream& out,string lname,string status)
    {
    
    
    out << left <<"Tax summary for "<<lname<<" family"<<endl;
    out<< left<<"Filling status: "<<status<<endl;
    }
    void getfilename(string filetype,string& filename)
    {
    cout << "Enter name of " << filetype << " file\n";
    cin >> filename;
    }
    
    void reformat (string lname)
    
    //Given a word, convert the first letter to upper case and the
    //rest of the letters to lower case. The converted word will
    //be passed back.
    {
    int wlen;
    wlen = lname.length();
    lname[0] = toupper(lname[0]);
    for (int i=1; i<wlen; i++)
    lname[i] = tolower(lname[i]);
    }
    is not capalizing the first words
    Tax summary for jones family
    Filling status: married
    this is my output
    i want jones named capatalize for exanple if the input is JoneS to come out has Jones
    thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Changes made in a function disappear when the function ends, unless you pass in the parameters using a reference type (string& instead of string).

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    3
    ok i did that
    Code:
    void reformat (string& lname)
    
    //Given a word, convert the first letter to upper case and the
    //rest of the letters to lower case. The converted word will
    //be passed back.
    {
      int wlen;
      wlen = lname.length();
      lname[0] = toupper(lname[0]);
      for (int i=1; i<wlen; i++)
        lname[i] = tolower(lname[i]);
    
    }
    but still doesnt work

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    reformat(lname);
    
    input >> lname;
    It's no good to process input before it comes in; C++ is not time travel.

    EDIT: Actually I'm looking at your loop weirdly, so this:
    Code:
    writeinfo(output,lname,status);
    reformat(lname);
    is the part that would require time travel.

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by tabstop View Post
    [code]
    ...C++ is not time travel.
    Sure it does:
    Code:
    #include <fluxcapacitor>
    ...
    using namespace 1.21gigawatts;
    ...
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 06-16-2011, 06:21 PM
  2. Replies: 5
    Last Post: 05-09-2010, 10:58 AM
  3. Replies: 1
    Last Post: 10-31-2005, 10:36 AM
  4. Replies: 7
    Last Post: 07-18-2005, 08:43 AM
  5. Problem comparing string from text file with string constant
    By XenoCodex Admin in forum C++ Programming
    Replies: 3
    Last Post: 07-25-2002, 10:17 AM

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