error C2065: ‘cout’ : undeclared identifier

I am working on the ‘driver’ part of my programing assignment and i keep getting this absurd error: error C2065: ‘cout’ : undeclared identifier I have even tried using the std::cout but i get another error that says: IntelliSense: namespace “std” has no member “cout” when i have declared using namespace std, included iostream + …

Read more

Append an int to a std::string

The std::string::append() method expects its argument to be a NULL terminated string (char*). There are several approaches for producing a string containg an int: std::ostringstream#include <sstream> std::ostringstream s; s << “select logged from login where id = ” << ClientID; std::string query(s.str()); std::to_string (C++11)std::string query(“select logged from login where id = ” + std::to_string(ClientID)); boost::lexical_cast#include <boost/lexical_cast.hpp> std::string query(“select logged from login …

Read more

printf with std::string?

It’s compiling because printf isn’t type safe, since it uses variable arguments in the C sense1. printf has no option for std::string, only a C-style string. Using something else in place of what it expects definitely won’t give you the results you want. It’s actually undefined behaviour, so anything at all could happen. The easiest way to fix this, since …

Read more

Why am I getting string does not name a type Error?

Your using declaration is in game.cpp, not game.h where you actually declare string variables. You intended to put using namespace std; into the header, above the lines that use string, which would let those lines find the string type defined in the std namespace. As others have pointed out, this is not good practice in headers — everyone who includes that header will also involuntarily hit the using line and import std into their …

Read more

Is there a tab equivalent of std::endl within the standard library?

No. std::endl isn’t a newline constant. It’s a manipulator which, in addition to inserting a newline, also flushes the stream. If you just want to add a newline, you’re supposed to just insert a ‘\n’. And if you just want to add a tab, you just insert a ‘\t’. There’s no std::tab or anything because inserting a tab plus flushing the stream is not exactly a common operation.

Issue with std::stol – ‘std::invalid_argument’ what(): stol

I have an issue with std::stol. All answers I have found regarding to issues with std::stol or std::stoi are dealing with C++11 compiling / building. When I use std::stol() I get the following error: Any ideas? Building with gcc -std::C++11 works fine. Note: I think this is my first C++11 expression I use.

Replace part of a string with another string

There’s a function to find a substring within a string (find), and a function to replace a particular range in a string with another string (replace), so you can combine those to get the effect you want: In response to a comment, I think replaceAll would probably look something like this: