Could someone help me with this?

ifstream readfromfile("stats.txt");

    readfromfile >> lvl >> xp >> str >> spd >> acc >> hp >> endl  >> inventory[0] >> endl  >> inventory[1] >> endl  >> inventory[2] >> endl     >> inventory[3] >> endl  >> inventory[4] >> endl  >> inventory[5] >> endl  >>inventory[6] >> endl  >> inventory[7] >> endl >> equipw >> endl;

The error I get is:

489 C:\Documents and Settings\MixPix\Mina dokument\C++\lvlsystemareas.cpp no match for 'operator>>' in '(+(+(+(+(+((std::basic_istream<char, std::char_traits<char> >*)(&readfromfile))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&lvl))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&xp))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&str))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&spd))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&acc))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(&hp))) >> std::endl'

Dani AI

Generated

Short answer: the compile error came from trying to use std::endl with the extraction operator. As pointed out, std::endl is an output manipulator (for std::ostream) and cannot be passed to operator>>. confirmed that removing the endl tokens fixed the build — that matches the reason below.

Why it failed: operator>> extracts into variables or accepts input manipulators for istream (like std::ws), but std::endl is an ostream manipulator. Putting >> std::endl makes the compiler try to match an extraction overload that accepts the endl function pointer, which doesn't exist, so you get the "no match for operator>>" message. Also note that extraction already skips white space (including newlines), so you normally do not need to read or consume a newline explicitly when using >>.

If inventory entries may contain spaces, prefer std::getline after consuming the leftover newline. Example pattern:

#include <fstream>
#include <string>
#include <limits>

std::ifstream in("stats.txt");
if (!in) /* handle error */;

int lvl, xp, str, spd, acc, hp;
in >> lvl >> xp >> str >> spd >> acc >> hp;   // no endl here

in.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // eat end-of-line

std::string inventory[8];
for (int i = 0; i < 8 && std::getline(in, inventory[i]); ++i) { }

std::string equipw;
std::getline(in, equipw);

Quick tips: use >> for single-word tokens and std::getline for multi-word lines; use in.ignore(...) or in >> std::ws to remove leftover newlines before getline; always check in.good()/in.fail() after reads; keep the save/load format consistent (a simple delimiter or one item per line makes parsing easier).

Recommended Answers

All 7 Replies

one of your variabes, does not support the >> operator.

Which type are the variables:
lvl
xp
str
spd
acc
hp
inventory?

one of your variabes, does not support the >> operator.

Which type are the variables:
lvl
xp
str
spd
acc
hp
inventory?

lvl - int
xp- int
str- int
spd- int
acc- int
hp - int
inventory - string

odd thing is that this works great when saving the file (this part is the loading function)

did you try without "endl"?

Sounds like an incredibly obvious and easy solution, I shall try that immediately :D

Worked great, thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.