Results 1 to 18 of 18

Thread: ASCII Number to Strings & Chars

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    47
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Exclamation ASCII Number to Strings & Chars

    I search for help online for a whole day, maybe 2.
    I outputted strings to its ascii value to a file by using the for loops and char .at()

    all these output went well, but how can i read it back from the file?

    i tried qt library and native c++ (not problem in codeblocks, but i want to have gui)

    I'm not sure how to use char array below because I wont know how long the string is, how many chars are there.
    And in my file, its not only 1 line of code. For example, when i input

    ABCD
    AAAA
    BBBB

    my file will become

    65 66 67 68
    65 65 65 65
    66 66 66 66

    Qt Code:
    1. ifstream myFile("abc.txt");
    2.  
    3. while(myFile >> a >> a1 >> a2){
    4.  
    5.  
    6. a = a - 1;
    7. a = a1 - 1;
    8. a= a2 - 1;
    9. QString abc = QChar( a + a1 + a2);
    10. ui->aLine->setText(abc);
    11. }
    To copy to clipboard, switch view to plain text mode 

    when i use just these codes below, it will only shows the first character of the whole strings.
    And is there a way to make the abc still usable outside the loop? cause i need to set it after the loops right? and it always shows not declared.

    Qt Code:
    1. myFile >> a
    2. QString abc = QChar( a );
    3. ui->aLine->setText(abc);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QFile mFile("abc.txt");
    2. mFile.open(QIODevice::ReadOnly | QIODevice::Text);
    3. QDataStream in(&mFile);
    4.  
    5. in >> a; // Not sure what's next. it keeps error
    To copy to clipboard, switch view to plain text mode 
    Last edited by ttimt; 26th November 2012 at 17:16.

Similar Threads

  1. qgetenv and special chars
    By miraks in forum Qt Programming
    Replies: 8
    Last Post: 24th October 2020, 01:05
  2. Replies: 1
    Last Post: 5th March 2012, 06:34
  3. QTextEdit 80 chars wide
    By mpi in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2011, 13:18
  4. Static casting of signed chars
    By ShamusVW in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2009, 05:46
  5. Need help. can't append chars in QString
    By AcerExtensa in forum Qt Programming
    Replies: 6
    Last Post: 12th June 2008, 10:57

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
  •  
Qt is a trademark of The Qt Company.