Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    CoderNever's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    https://mpgh.net MPGHCash: $700,458,011
    Posts
    1,198
    Reputation
    131
    Thanks
    2,236
    My Mood
    Buzzed

    Very Simple Noob Request [C++]

    Well I am working on C++, but I just want to know how..to read text from a file and display that text in a messagebox.

  2. #2
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    Search on MSDN/Google for Input/Output Streams ; They are the ones that will allow you to read from files =).

    Saying more would kill all the fun.

    Enjoy.

    For The Display part, Once your String is buffered, It's pretty easy too, Expecially if you use MiCrapSoft .Net
    Love You All~

  3. The Following User Says Thank You to Melodia For This Useful Post:

    CoderNever (06-16-2010)

  4. #3
    CoderNever's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    https://mpgh.net MPGHCash: $700,458,011
    Posts
    1,198
    Reputation
    131
    Thanks
    2,236
    My Mood
    Buzzed
    Lol the fun is already killed when your computer crashes everytime you think the code might work.
    Last edited by CoderNever; 06-16-2010 at 08:32 PM.

  5. #4
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    Hm.

    How could you possibly have such a Memory Leak with "Safe" allocations... Meah~

    Well, You found your way around with these Streams ? Or you need an more concrete Example ?.
    Love You All~

  6. #5
    CoderNever's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    https://mpgh.net MPGHCash: $700,458,011
    Posts
    1,198
    Reputation
    131
    Thanks
    2,236
    My Mood
    Buzzed
    btw I searched and got this

    Code:
      #include<fstream.h>
        int main()
        {
            char str[2000];
            fstream file_op("c:\\test_file.txt",ios::in);
            while(file_op >> str)
            cout << str ;
     
            file_op.close();
    
            return 0;
        }
    what would I use to save it to a variable..or is "str" the variable I would use??

  7. #6
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    If you want to read only from file, You are better to do an ifstream instead of an fstream.

    Yaps, str will be your string ( Well.. Char[2000] ), And the cout line will print the result to console.

    ( Pheraps You should do Basic C++ Tutorials/Courses/Books =), Could teach you a lot of basis, And Streams are in these Basis before attempting stuff. =) )
    Love You All~

  8. #7
    CoderNever's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    https://mpgh.net MPGHCash: $700,458,011
    Posts
    1,198
    Reputation
    131
    Thanks
    2,236
    My Mood
    Buzzed
    Im very confused I have the includes in place, and I am getting all these errors...I am testing in a windows form first...and when I get the code to work I want to move it to a Dll Project..;s The funny thing is I code Java, and Grand Theft Auto Private...which is bassed of C++...and I code that just fine this should not be so confusing..but it is..

    My Code

    Code:
    ifstream f("test.txt");
    f>>n;
    f.close();
    cout<<n;
    cin.get();
    Errors

    Code:
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(30) : error C2065: 'ifstream' : undeclared identifier
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(30) : error C2146: syntax error : missing ';' before identifier 'f'
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(30) : error C3861: 'f': identifier not found
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(31) : error C2065: 'f' : undeclared identifier
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(31) : error C2065: 'n' : undeclared identifier
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(32) : error C2065: 'f' : undeclared identifier
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(32) : error C2228: left of '.close' must have class/struct/union
    1>        type is ''unknown-type''
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(33) : error C2065: 'cout' : undeclared identifier
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(33) : error C2065: 'n' : undeclared identifier
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(34) : error C2065: 'cin' : undeclared identifier
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(34) : error C2228: left of '.get' must have class/struct/union
    1>        type is ''unknown-type''
    Last edited by CoderNever; 06-16-2010 at 09:01 PM.

  9. #8
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    Oh.

    Bad Start.

    Windows Forms Library use .Net/Managed C++

    The code you have is Native C++.

    So, Two things ; Porting your code back and forth from Native to Managed C++ isn't easy for someone that beggins coding, And These do not use all the same methods anyways.

    So, You should start directly with your DLL, And it should not cry too much, But as I said previously ; Are you sure this is the easiest thing to begin with ?
    Love You All~

  10. #9
    CoderNever's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    https://mpgh.net MPGHCash: $700,458,011
    Posts
    1,198
    Reputation
    131
    Thanks
    2,236
    My Mood
    Buzzed
    Lol Yes...I need to do something else with it..that is to confusing to explain....so I asked for a read from file to messagebox..for I can mess around with the code and make it to something different..so if you can spoon feed me that code that would work for a .dll that would be extremely awesome of you.

  11. #10
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    I could post right below the code you want but you wouldn't have learned a thing.

    Are you sure you don't want to start easily ?

    Anyways, For messageboxs, You need the "stdio" header, The code is MessageBox/MessageBoxA,

    And you are alright with "your" code to get the string from file, At one exception; You need to use the namespace std for this to work ( using namespace std; ) Below your includes and stuff, And cut off the cout part, As this is CLI Code.

    But as I said, This taught you nothing.
    Love You All~

  12. #11
    CoderNever's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    https://mpgh.net MPGHCash: $700,458,011
    Posts
    1,198
    Reputation
    131
    Thanks
    2,236
    My Mood
    Buzzed
    it taught me alot, I learn by analyzing codes giving to me, and re looking them and changing them to different things.


    ok I updated my code


    Code:
    ifstream f("test.txt");
    f>>n;
    f.close();
    cin.get();
    now i get these errors

    Code:
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(34) : error C2061: syntax error : identifier 'n'
    1>c:\users\michael\documents\visual studio 2008\projects\combat arm console\combat arm console\combat arm console.cpp(36) : error C2065: 'n' : undeclared identifier
    I'm guessing I have to define N as a string? now how would I do that?

    update..i guessing to use

    char n to define n as a string
    and if thats right my last error is

    Code:
    syntax error : missing ';' before identifier 'ifstream'
    Last edited by CoderNever; 06-16-2010 at 09:31 PM.

  13. #12
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    Declare your "n", Lawl.

    If you follow your example ;

    char n[2000];

    Edit -->

    You forgot the ";" at the end of your declaration.

    need to learn Basics. Again <3
    Last edited by Melodia; 06-16-2010 at 09:35 PM.
    Love You All~

  14. The Following 2 Users Say Thank You to Melodia For This Useful Post:

    Hell_Demon (06-16-2010),why06 (06-16-2010)

  15. #13
    CoderNever's Avatar
    Join Date
    Feb 2009
    Gender
    female
    Location
    https://mpgh.net MPGHCash: $700,458,011
    Posts
    1,198
    Reputation
    131
    Thanks
    2,236
    My Mood
    Buzzed
    no i had the ; at the end the reason i got the error is cause the string was un defined and when ifstream was spaced next to f(""); with out a ; it was a undefined identifier

  16. #14
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Why not try doing wat u said.
    it taught me alot, I learn by analyzing codes giving to me, and re looking them and changing them to different things.
    except instead of changing things randomly take the time to learn why it doesn't work. Or better yet learn to read error messages.

    wth am I up at 6:40 am, i dont fkin know.... =/

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  17. #15
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    String is not an Native C++ term.

    I Say string, But It's char*, Too used to Managed C++, Sowwies.

    @Why
    Lawl, Well, 7:41 Here, Guess I should get some sleep, I woke up..... ~50 Hours ago ?
    Love You All~

Page 1 of 2 12 LastLast

Similar Threads

  1. Very Simple Request
    By InCognito in forum Help & Requests
    Replies: 5
    Last Post: 04-06-2010, 12:46 AM
  2. Will buy hacks for very simple game
    By newbiespark in forum Suggestions, Requests & General Help
    Replies: 2
    Last Post: 01-17-2009, 07:05 AM
  3. Very simple WR Hack
    By akilli in forum WarRock - International Hacks
    Replies: 13
    Last Post: 07-25-2007, 10:25 PM
  4. Very simple WR Hack
    By akilli in forum WarRock - International Hacks
    Replies: 4
    Last Post: 07-25-2007, 08:48 PM
  5. Very Odd Signature Request...
    By Mikoll in forum Help & Requests
    Replies: 4
    Last Post: 02-06-2006, 09:03 PM