Problem: the first letter in my strings are being truncated except the first string.

This is a discussion on Problem: the first letter in my strings are being truncated except the first string. within the C++ Programming forums, part of the General Programming Boards category; Ok, when I have problems I do try to search ebay, use the search function of the forums, so if ...

  1. #1
    Compile Errors = Schwa?!
    Join Date
    Aug 2005
    Location
    Ohio
    Posts
    15

    Problem: the first letter in my strings are being truncated except the first string.

    Ok, when I have problems I do try to search ebay, use the search function of the forums, so if I'm asking a often asked question, sorry I tried, alright on to the problem.


    I'm writing a program to input user info/stats and output html, as a way to learn basic C++ coding and make something kinda usefull . I go through all the input, and when I check the HTML the first letter in all the places where a variable was, is "truncated" from the beginning by one character.

    Here's the code (Also any input on how to display quotes other than << (char) 34 << would be appreciated ):


    Code:
     
    //---Header---//
    #include <cstdlib>
    #include <iostream>
    #include <stdio.h>
    #include <fstream>
    //---End Header---//
    
    //---Shortcuts---//
    using namespace std;
    //---End Shortcuts---//
    
    int main(int argc, char *argv[])
    {
        
         string NewPlayerName;
         string PlayerName;
         string FileName;
         string ProfilePicName;
         
         cout<<"New Player\n\n";
         cout<<"First/Last Name: ";
         cin.get();
         getline(cin , NewPlayerName , '\n');
         
         PlayerName = NewPlayerName;
         FileName = NewPlayerName += ".html";
         ofstream Playername( FileName.c_str() );
         //Where I would have loads of HTML
         cout<< NewPlayerName << "\n";
         cout<< FileName << "\n";
         
         cout<<"Profile Picture Name (Include the extension ex: .jpg): ";
         cin.get();
         getline(cin , ProfilePicName , '\n');
         cout<< ProfilePicName;
        
        
        Playername<< PlayerName << "," << FileName << "," << ProfilePicName << "\n"; 
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
    //That's better ;)
    Last edited by Howie17; 09-02-2005 at 04:22 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,743
    It might be better to come up with the smallest and simplest program that demonstrates this problem.

    Also any input on how to display quotes other than << (char) 34 << would be appreciated
    cout << "\"";
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > Sorry, if its annoying to read because it extends too far off the screen.
    1. Use multiple lines
    2. You don't have to end a statement at newlines.

    Code:
        Playername
            << "<td width=\"13%\"><div align=\"center\"><strong>"
            << "<font face=\"Arial, Helvetica, sans-serif\">Date</font></strong></div></td>\n"
            << "<td width=\"12%\"><div align=\"center\"><strong>"
            << "<font face=\"Arial, Helvetica, sans-serif\">Game</font></strong></div></td>\n"
            << "<td width=\"15%\"><div align=\"center\"><strong>"
            << "<font face=\"Arial, Helvetica, sans-serif\">Venue</font></strong></div></td>\n"
            << "<td width=\"18%\"><div align=\"center\"><strong>"
            << "<font face=\"Arial, Helvetica, sans-serif\">Finished</font></strong></div></td>\n"
            << "<td width=\"22%\"><div align=\"center\"><strong>"
            << "<font face=\"Arial, Helvetica, sans-serif\">Busted By</font></strong></div></td>\n";
    You could even break it up even more, and make the indentation reflect the HTML nesting if you think it will help you write better HTML output (like matching all the begin/end tags).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Could there be a logical fault with your program causing the output to be truncated by one letter?

  5. #5
    Compile Errors = Schwa?!
    Join Date
    Aug 2005
    Location
    Ohio
    Posts
    15
    Alright, I cut out all the un-neccesary code to the actual problem, so thats updated.

    You could even break it up even more, and make the indentation reflect the HTML nesting if you think it will help you write better HTML output (like matching all the begin/end tags).
    -I plan to go back through and do that, I agree it'd help in alot of ways.


    oh btw, thanks for posting that Salem, I forgot you could do the:

    Code:
    Playername 
    << HTML
    << HTML
    << HTML etc. whatever this is called ;)
    Last edited by Howie17; 09-02-2005 at 04:28 AM.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Well the get() before the getline() will truncate.
    Stick to getline() for everything, then extract information. Trying to mix and match various input styles usually leads to grief.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Compile Errors = Schwa?!
    Join Date
    Aug 2005
    Location
    Ohio
    Posts
    15
    Ah, hehe I feel so nooby when the fixes are so easy.. but if the fixes were harder I guess I'd get frustrated with writing multiple lines of code to accomplish minuscule tasks.

    Thanks for the quote tip LaserLight, and thanks for the fix Salem. Have you guys been up all night? or early risers? (I haven't slept yet)

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > Have you guys been up all night? or early risers?
    This is an international board - try not to be so US-centric.
    It's midday here
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. string pattern search problem
    By goron350 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 07:50 AM
  4. Replies: 5
    Last Post: 05-25-2004, 04:36 PM
  5. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM

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