Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:42:21+00:00 2026-06-01T09:42:21+00:00

I was trying for the first time to read data from a file, a

  • 0

I was trying for the first time to read data from a file, a .txt file. Below is my code:

Level::ReadStream(std::fstream data)
{
bool write = false;
char* p = data.tellg();

while(!data.eof())
{
    int i = 0, j = 0;

    if(&p == '[')
    {
        write == true;
    }

    if(write == true)
    {
        mapX[i] = p;
        mapY[j] = p;
    }

    if(&p == '/n')
    {
        i++;
        j++;
    }

    else
    {
        i++;
    }

    *p++
}
};

void Level::SetMapSize(std::fstream data)
{
int* p = data.tellg();
int sizeX = 0;
int sizeY = 0;

while(!data.eof())
{
    if(&p != '[' && &p != ']' && &p != '\n')
    {
        sizeX++;
    }

    else if(&p != '\n')
    {
        sizeY++;
    }
}

mapX.resize(sizeX);
mapY.resize(sizeY);

std::cout << sizeX << '\n' << sizeY;
};

The goal of these two functions are to:
1- read all the chars in the file and, if the current character is not a bracket, add it to an index map(X, Y), then increase the counter so the next non-bracket value will be put in the correct index.

2- read all the file and, as before, count the non-bracket values, so it can make mapX and mapY the correct size.

However, it’s not working, and I got these errors:

 C:\...\Level.cpp|58|warning: multi-character character constant|

 c:\...\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\ios_base.h|790|error: 'std::ios_base::ios_base(const std::ios_base&)' is private|

 c:\...\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\iosfwd|47|error: within this context|

 c:...\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\iosfwd|87|note: synthesized method 'std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)' first required here |

 c:...\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\streambuf|770|error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]' is private|

 c:...\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\iosfwd|78|error: within this context|

 c:...\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\iosfwd|87|note: synthesized method 'std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)' first required here |

C:...\Level.cpp||In constructor 'Level::Level()':|

C:...\Level.cpp|24|note: synthesized method 'std::basic_fstream<char, std::char_traits<char> >::basic_fstream(const std::basic_fstream<char, std::char_traits<char> >&)' first required here |

C:...\Level.cpp|24|error:   initializing argument 1 of 'void Level::SetMapSize(std::fstream)'|

C:...\Level.cpp|29|error: 'cout' was not declared in this scope|

C:...\Level.cpp|38|error: ISO C++ forbids declaration of 'ReadStream' with no type|

C:...\Level.cpp|38|error: prototype for 'int Level::ReadStream(std::fstream)' does not match any in class 'Level'|

C :...\Level.cpp|17|error: candidate is: void Level::ReadStream(std::fstream)|
C:...\Level.cpp||In member function 'void Level::SetMapSize(std::fstream)':|
C:...\Level.cpp|75|error: invalid conversion from 'std::streamoff' to 'int*'|
C:...\Level.cpp|81|error: ISO C++ forbids comparison between pointer and integer|
C:...\Level.cpp|81|error: ISO C++ forbids comparison between pointer and integer|
C:...\Level.cpp|81|error: ISO C++ forbids comparison between pointer and integer|
C:...\Level.cpp|86|error: ISO C++ forbids comparison between pointer and integer|
C:...\Level.cpp|95|error: 'cout' is not a member of 'std'|
||=== Build finished: 15 errors, 1 warnings ===|

Can anyone help?

EDIT: Ok, I changed everything. My new code is:

void Level::ReadStream()
{
long p = textData.tellg();
int counter = 0;
int i = 0;
int j = 0;
char ch;

while(p != textData.eof())
{
    textData.seekg(counter);
    textData >> ch;

    if(ch != '[' && ch != ']')
    {
        mapX[i] = ch;
        mapY[j] = ch;

        i++;

        if(ch == '\n')
        {
            i = 0;
            j++;
        }
    }

    counter++;
    p = textData.tellg();
}
};

with mapX and mapY being 5 int long. Now it compiles, but hangs and crashes. I don’t see why… Is there anyone that can help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:42:22+00:00Added an answer on June 1, 2026 at 9:42 am

    It’s \n not /n! That should clear some errors.

    Also, you can’t just take the pointer from tellg — it returns the position, not the pointer to the position!

    Basically try to read up on IO in C++, maybe start with this question:

    How to read from a file char by char in C++?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read data from a text file and assign it to arrays.
I'm trying to read data from a.csv file to ouput it on a webpage
its my first time to access and read an excel file (xlsx) with c#..
I'm trying to obtain data using regular expressions from a html file, by implementing
I am trying to extract contents from a txt file. This file is dynamic
Using Python (3.1 or 2.6), I'm trying to read data from binary data files
I'm trying to input data from an XML file in a C++ program using
Iam trying to read data from a table. Initially it is empty. If i
First time trying to deal with users logging in with ASP.net and haven't had
this is my first time trying to use document classes in AS3 and im

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.