Thread: Read text file char by char by using vector class

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    95

    Read text file char by char by using vector class

    Code:
    cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
    cin>>filename;
    ifstream inpfile;
    inpfile.open(filename,ios::in);
    if(inpfile.is_open())
    {
    inpfile>>width;
    inpfile>>height;
    }
    else
    {
    cout<<"invalid file"<<endl;
    }
    std::vector<Cell> row;
    for (int i = 0; i < livingCells.size(); i++)
    { 
    inpfile.getline(board,255);
    livingCells.push_back(row);
    }
    thanks billions

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    Thanks for what? This is the same thing you did in your last thread. We're not going to just do your work for you; at least, I'm not. What the heck is Cell? Why are you pushing copies of a vector into (what I think is) another vector? You're not even reading data into a vector. You're just putting random things in random places.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

  4. #4
    Registered User
    Join Date
    Mar 2014
    Posts
    95
    this program is gameoflife and i have two class
    1.cell is class that has
    private int x ,int y
    and have construnctor that take 2 argument like :cell(x,y) so
    i call this cell class as vector
    2.gameoflife
    private:
    vector<cell>livingcell
    how i can initial read from text file

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Ph0x
    1.cell is class that has
    private int x ,int y
    and have construnctor that take 2 argument like :cell(x,y)
    I see. So, what is the purpose of the x and y member variables? It may sound obvious to you, it might even be obvious to me, but you need to spell it out, not just assume.

    Quote Originally Posted by Ph0x
    i call this cell class as vector
    What do you mean?

    Quote Originally Posted by Ph0x
    2.gameoflife
    private:
    vector<cell>livingcell
    I note that in its original form, John Conway's Game of Life uses a two dimensional grid.

    Quote Originally Posted by Ph0x
    how i can initial read from text file
    What is the file format?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Mar 2014
    Posts
    95
    cell is class that has x and y so the format of file is text you can read like this x for alive - for dead
    x---x
    xxx-

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Ph0x
    cell is class that has x and y
    You have not answered my question: what is the purpose of the x and y member variables?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It really helps if you provide a complete minimal example of what you're trying to do. It should also compile.
    When you ask questions, ask specific questions. Just saying "thanks billions" doesn't help (we can't read your mind). Provide input data to reproduce your issue (like input files, etc).
    Also, code speaks louder than words. Instead of trying to explain with words, explain with code.

    Put yourself in our situation. What would YOU need from a stranger in order to solve his/her problems?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    I thought I knew what he meant by x and y too, but then he turned my assumption into pudding.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read Strings From Text File Into Char Array
    By somniferium in forum C Programming
    Replies: 8
    Last Post: 09-13-2012, 12:41 AM
  2. Read char by char into two-dimensional array pointer.
    By 'Serj Codito in forum C++ Programming
    Replies: 5
    Last Post: 09-08-2012, 09:47 AM
  3. Replies: 9
    Last Post: 04-04-2008, 12:41 PM
  4. cant read last char from a file
    By aze in forum C Programming
    Replies: 8
    Last Post: 04-25-2004, 05:20 PM
  5. Read File To Char Array with Null char init
    By MicroFiend in forum Windows Programming
    Replies: 1
    Last Post: 10-28-2003, 06:18 PM