Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

why remove_if function generate extra variables after removing space?

$
0
0
string s(" how are you");

remove_if(s.begin(), s.end(), isspace);

cout<<s;

why the output is "howareyouou" instead of "howareyou"?

Alternative to GetDiskFreeSpace

$
0
0

The GetDiskFreeSpace method returns values for NumberOfFreeClusters and TotalNumberOfClusters based on what is "available to the user who is associated with the calling thread".  This limitation means that the values returned are different depending on network quotas, etc..

I need an alternative in C++ to GetDiskFreeSpace that does not have this limitation and that will return the same values (after you do the multiplication) as the Windows Explorer properties dialog does for a mounted drive.

Is there a more accurate alternative to GetDiskFreeSpace in C++?

namespaces

$
0
0

Hi

I am stuck. please can someone be of help. am learning c++ using these textbook. I was asked as part of an exercise,  to organise some programs into their own namespaces and  compile the whole program. I have divided these into two. (a) the original programs( not in namespaces ) and  (b) how I tried to solve the problem ( with the programs in their own namespaces ) I was getting these error messages. Microsoft visual studio 2015 compiler

1) Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "class chapter_15::Query __cdecl chapter_15::operator|(class chapter_15::Query const &,class chapter_15::Query const &)" (??Uchapter_15@@YA?AVQuery@0@ABV10@0@Z) referenced in function _main namespaces_chapter_18 C:\Users\evan_2\Documents\Visual Studio 2015\Projects\namespaces_chapter_18\namespaces_chapter_18\namespaces_chapter_18.obj 1 

2) Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "class chapter_15::Query __cdecl chapter_15::operator&(class chapter_15::Query const &,class chapter_15::Query const &)" (??Ichapter_15@@YA?AVQuery@0@ABV10@0@Z) referenced in function _main namespaces_chapter_18 C:\Users\evan_2\Documents\Visual Studio 2015\Projects\namespaces_chapter_18\namespaces_chapter_18\namespaces_chapter_18.obj 1 

3) Severity Code Description Project File Line Suppression State

Error LNK2019 unresolved external symbol "public: __thiscall chapter_15::Query::Query(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Query@chapter_15@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main namespaces_chapter_18 C:\Users\evan_2\Documents\Visual Studio 2015\Projects\namespaces_chapter_18\namespaces_chapter_18\namespaces_chapter_18.obj 1 

4)Severity Code Description Project File Line Suppression State
Error LNK1120 3 unresolved externals namespaces_chapter_18 C:\Users\evan_2\Documents\Visual Studio 2015\Projects\namespaces_chapter_18\Debug\namespaces_chapter_18.exe 1 

I know what LNK2019 means, but I don't know what am doing wrong

here goes the codes

(a) the original codes

textquery.cpp : - broken down into textquery.cpp and textquery.h , in my solution

// textquery_main.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<new>
#include<memory>
#include<bitset>
#include<fstream>
#include<sstream>
#include<map>
#include<set>
using namespace std;
using line_no = std::vector<std::string>::size_type;
class QueryResult; // declaration needed for return type in the query function
class TextQuery
{
public:
 //using line_no = std::vector<std::string>::size_type;
 TextQuery(std::ifstream&);
 QueryResult query(const std::string&) const;
 TextQuery(const TextQuery &Tq) : file(make_shared<std::vector<std::string>>(*(Tq.file))) // copy constructor
 {
  for (auto x = Tq.wm.begin(); x != Tq.wm.end(); ++x)
  {
   wm[x->first] = make_shared<set<line_no>>(*(x->second));
  }
 }
 TextQuery &operator=(const TextQuery &Tq)
 {
  file = make_shared<std::vector<std::string>>(*(Tq.file));
  for (auto x = Tq.wm.cbegin(); x != Tq.wm.cend(); ++x)
  {
   wm[x->first] = make_shared<set<line_no>>(*(x->second));
  }
  return *this;
 }
 ~TextQuery(){}
private:
 std::shared_ptr<std::vector<std::string>> file; // input file
 //map of each word to the set of the lines in which that word appears
 std::map<std::string, std::shared_ptr<std::set<line_no>>> wm;
};
// read the input file and build the map of lines to line numbers
TextQuery::TextQuery(ifstream &is):file(new vector<string>)
{
 string text;
 while (getline(is, text))
 {
  // for each line in the file
  (file)->push_back(text); // remember this line of text
  int n = (file)->size() - 1; // the current line number
  istringstream line(text); // separate the line into words
  string word;
  while (line >> word)
  { // for each word in that line
    // if word isn't already in wm, subscripting adds a new entry
   auto &lines = wm[word]; // lines is a shared_ptr
   if (!lines) // that pointer is null the first time we see word
    lines.reset(new set<line_no>); // allocate a new set
   lines->insert(n); // insert this line number
  }
 }
}
class QueryResult {
 friend std::ostream& print(std::ostream&, const QueryResult&);
public:
 QueryResult(std::string s, std::shared_ptr<std::set<line_no>> p, std::shared_ptr<std::vector<std::string>> f) : sought(s), lines(p), file(f) { }
 QueryResult(const QueryResult &Qr) : sought(Qr.sought),lines(make_shared<std::set<line_no >>(*(Qr.lines))), file(make_shared<std::vector<std::string>>(*(Qr.file))){}
 QueryResult &operator=(const QueryResult &Qr)
 {
  sought = Qr.sought;
  lines = make_shared<std::set<line_no >>(*(Qr.lines));
  file = make_shared<std::vector<std::string>>(*(Qr.file));
  return *this;
 }
 ~QueryResult(){}
 set<line_no>::iterator begin() const;
 //TextQuery(const TextQuery &Tq) : file(make_shared<std::vector<std::string>>(*(Tq.file)))
 set<line_no>::iterator end() const;
 std::shared_ptr<std::vector<std::string>> get_file() const;
private: std::string sought; // word this query represents
   std::shared_ptr<std::set<line_no>> lines; // lines it's on
   std::shared_ptr<std::vector<std::string>> file; // input file
};
QueryResult TextQuery::query(const string &sought) const
{ // we'll return a pointer to this set if we don't find sought
 static shared_ptr<set<line_no>> nodata(new set<line_no>);
 // use find and not a subscript to avoid adding words to wm!
 auto loc = wm.find(sought);
 if (loc == wm.end())
  return QueryResult(sought, nodata, file); // not found
 else
  return QueryResult(sought, loc->second, file);
}
set<line_no>::iterator QueryResult::begin() const
{
 return (*lines).begin();
}
set<line_no>::iterator QueryResult::end() const
{
 return lines->end();
}

std::shared_ptr<std::vector<std::string>> QueryResult::get_file() const
{
 return file;
}
ostream &print(ostream & os, const QueryResult &qr)
{ // if the word was found, print the count and all occurrences
 os << qr.sought << " occurs " << qr.lines->size() << " " << ((qr.lines->size() > 1) ? "times" : "time") << endl;
 // print each line in which the word appeared
 for (auto num : *qr.lines) // for every element in the set
          // don't confound the user with text lines starting at 0
  os << "\t(line " << num + 1 << ") " << *(qr.file->begin() + num) << endl;
 return os;
}

query_base.cpp : - includes textquery.cpp as textquery.h

#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<new>
#include<memory>
#include<bitset>
#include<fstream>
#include<sstream>
#include<map>
#include<set>
#include"Text_Query.h"
#include<algorithm>
#include<iterator>
using namespace std;
// abstract class acts as a base class for concrete query types; all members are private
class Query_base{
 friend class Query;
protected:
 using line_no = TextQuery::line_no; // used in the eval functions
 virtual ~Query_base() = default;
private: // eval returns the QueryResult that matches this Query
 virtual QueryResult eval(const TextQuery&) const = 0; // rep is a string representation of the query
 virtual std::string rep() const = 0;
};
// interface class to manage the Query_base inheritance hierarchy
class Query { // these operator need access to the shared_ptr constructor
 friend Query operator~(const Query &);
 friend Query operator|(const Query&, const Query&);
 friend Query operator&(const Query&, const Query&);
public:
 Query(const std::string&); // builds a new WordQuery // interface functions: call the corresponding Query_base operations
 QueryResult eval(const TextQuery &t) const
 {
   return q ->eval(t);
 }
 std::string rep() const { cout << "Query rep member"; return q->rep(); }
private:
 Query(std::shared_ptr<Query_base> query) : q(query) { }
 std::shared_ptr<Query_base> q;
};
 
std::ostream & operator<<(std::ostream &os, const Query &query)
{ // Query::rep makes a virtual call through its Query_base pointer to rep()
 return os << query.rep();
}
   
class WordQuery : public Query_base {
 friend class Query; // Query uses the WordQuery constructor
 WordQuery (const std::string &s) : query_word(s) { cout << "WordQuery constructor" << query_word; } // concrete class: WordQuery defines all inherited pure virtual functions
 QueryResult eval(const TextQuery &t) const {
  return t.query(query_word);
 }
 std::string rep() const { cout << "WordQuery rep member"; return query_word; }
 std::string query_word; // word for which to search
   
};
   
inline Query::Query(const std::string &s) : q(new WordQuery(s)) { cout << "Query constructor"; }
   
class NotQuery : public Query_base {
 friend Query operator~(const Query &);
 NotQuery(const Query &q) : query(q) { cout << "NotQuery constructor"; } // concrete class: NotQuery defines all inherited pure virtual functions
 std::string rep() const
 {
  cout << "NotQuery rep member"; return "~(" + query.rep() + ")";
 }
 QueryResult eval(const TextQuery&) const;
 Query query;
   
};
inline Query operator~(const Query &operand) {
 return std::shared_ptr<Query_base>(new NotQuery(operand));
}
   
class BinaryQuery : public Query_base {
protected:
 BinaryQuery(const Query &l, const Query &r, std::string s) : lhs(l), rhs(r), opSym(s) { cout << "BinaryQuery constructor"; } // abstract class: BinaryQuery doesn't define eval
 std::string rep() const
 {
  cout << "BinaryQuery rep member";
  return "(" + lhs.rep() + " " + opSym + " " + rhs.rep() + ")";
 }
 Query lhs, rhs; // right-and left - hand operands
 std::string opSym; // name of the operator
};
       
class AndQuery : public BinaryQuery {
 friend Query operator& (const Query&, const Query&);
 AndQuery(const Query &left, const Query &right) : BinaryQuery(left, right, "&") { cout << "AndQuery constructor"; } // concrete class: AndQuery inherits rep and defines the remaining pure virtual
 QueryResult eval(const TextQuery&) const;
      
};
inline Query operator&(const Query &lhs, const Query &rhs) {
 return std::shared_ptr<Query_base>(new AndQuery(lhs, rhs));
}
       
class OrQuery : public BinaryQuery {
 friend Query operator|(const Query&, const Query&);
 OrQuery(const Query &left, const Query &right) : BinaryQuery(left, right, "|") { cout << "OrQuery constructor"; }
 QueryResult eval(const TextQuery&) const;
       
};
inline Query operator|(const Query &lhs, const Query &rhs)
{
 return std::shared_ptr<Query_base>(new OrQuery(lhs, rhs));
}
// returns the union of its operands' result set s
QueryResult OrQuery::eval(const TextQuery& text)const
{ // virtual calls through the Query members, lhs and rhs // the calls to eval return the QueryResult for each operand
 auto right = rhs.eval(text), left = lhs.eval(text); // copy the line numbers from the left - hand operand into the result set
 auto ret_lines = make_shared<set<line_no>>(left.begin(), left.end());
 // insert lines from the right-hand operand
 ret_lines->insert(right.begin(), right.end()); // return the new QueryResult representing the union of lhs and rhs
 return QueryResult(rep(), ret_lines, left.get_file());
}
// returns the intersection of its operands' result set s
QueryResult AndQuery::eval(const TextQuery& text) const
{ // virtual calls through the Query operands to get result set s for the operands
 auto left = lhs.eval(text), right = rhs.eval(text); // set to hold the intersection of left and right
 auto ret_lines = make_shared<set<line_no>>(); // writes the intersection of two ranges to a destination iterator // destination iterator in this call adds elements to ret
   set_intersection(left.begin(), left.end(), right.begin(), right.end(), inserter(*ret_lines, ret_lines ->begin()));
   return QueryResult(rep(), ret_lines, left.get_file());
}
// returns the lines not in its operand's result set
QueryResult NotQuery::eval(const TextQuery&text) const
{ // virtual call to eval through the Query operand
 auto result = query.eval(text); // start out with an empty result set
 auto ret_lines = make_shared<set<line_no>>(); // we have to iterate through the lines on which our operand appears
 auto beg = result.begin(), end = result.end(); // for each line in the input file, if that line is not in result, // add that line number to ret_lines
 auto sz = result.get_file()->size();
 for (size_t n = 0; n != sz; ++n)
 { // if we haven't processed all the lines in result
   // check whether this line is present
  if (beg == end || *beg != n)
   ret_lines->insert(n);
  // if not in result, add this line
  else if (beg != end)
   ++beg; // otherwise get the next line number in result if there is one
 }
 return QueryResult(rep(), ret_lines, result.get_file());
}

b) my solution. contains 5 files.

(I) namespaces_chapter_18.cpp, the main program

#include "stdafx.h"
#include"query_base_namespace.h"
#include"Textquery_namespace.h"
int main(int argc, char *argv[])
{
 using namespace std;
 using chapter_15::Query;
 using chapter_12::TextQuery;
 using chapter_15::AndQuery;
 using chapter_15::OrQuery;
 using chapter_15::WordQuery;
 using chapter_15::operator&;
 using chapter_15::operator|;
 using chapter_12::print;
 ifstream Input_file(argv[1]);
 TextQuery Tq(Input_file);
 Query q = Query("fiery") & Query("bird") | Query("wind");
 cout << endl;
 print(cout, q.eval(Tq));
    return 0;
}

(ii) textquery_namespace.h, a header file

#pragma once
#ifndef TEXTQUERY_NAMESPACE
#define TEXTQUERY_NAMESPACE
#include<iostream>
#include<vector>
#include<string>
#include<new>
#include<memory>
#include<bitset>
#include<fstream>
#include<sstream>
#include<map>
#include<set>
//#include"Text_Query.h"
#include<algorithm>
#include<iterator>
namespace chapter_12
{
 //using namespace std;
 using std::set;
 using std::make_shared;
 typedef std::vector<std::string>::size_type line_no;
 class QueryResult; // declaration needed for return type in the query function
 class TextQuery
 {
 public:
  //using line_no = std::vector<std::string>::size_type;
  TextQuery(std::ifstream&);
  QueryResult query(const std::string&) const;
  TextQuery(const TextQuery &Tq) : file(make_shared<std::vector<std::string>>(*(Tq.file))) // copy constructor
  {
   for (auto x = Tq.wm.begin(); x != Tq.wm.end(); ++x)
   {
    wm[x->first] = make_shared<set<line_no>>(*(x->second));
   }
  }
  TextQuery &operator=(const TextQuery &Tq)
  {
   file = make_shared<std::vector<std::string>>(*(Tq.file));
   for (auto x = Tq.wm.cbegin(); x != Tq.wm.cend(); ++x)
   {
    wm[x->first] = make_shared<set<line_no>>(*(x->second));
   }
   return *this;
  }
  ~TextQuery() {}
 private:
  std::shared_ptr<std::vector<std::string>> file; // input file
              //map of each word to the set of the lines in which that word appears
  std::map<std::string, std::shared_ptr<std::set<line_no>>> wm;
 };
 class QueryResult {
  friend std::ostream& print(std::ostream&, const QueryResult&);
 public:
  QueryResult(std::string s, std::shared_ptr<std::set<line_no>> p, std::shared_ptr<std::vector<std::string>> f) : sought(s), lines(p), file(f) { }
  QueryResult(const QueryResult &Qr) : sought(Qr.sought), lines(make_shared<std::set<line_no >>(*(Qr.lines))), file(make_shared<std::vector<std::string>>(*(Qr.file))) {}
  QueryResult &operator=(const QueryResult &Qr)
  {
   sought = Qr.sought;
   lines = make_shared<std::set<line_no >>(*(Qr.lines));
   file = make_shared<std::vector<std::string>>(*(Qr.file));
   return *this;
  }
  ~QueryResult() {}
  set<line_no>::iterator begin() const;
  //TextQuery(const TextQuery &Tq) : file(make_shared<std::vector<std::string>>(*(Tq.file)))
  set<line_no>::iterator end() const;
  std::shared_ptr<std::vector<std::string>> get_file() const;
 private: std::string sought; // word this query represents
    std::shared_ptr<std::set<line_no>> lines; // lines it's on
    std::shared_ptr<std::vector<std::string>> file; // input file
 };
 std::ostream& print(std::ostream&, const QueryResult&);
}

#endif // !1

(iii) textquery_namespace.cpp, source file

// namespaces_chapter_18.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include"Textquery_namespace.h"
//using namespace std;
namespace chapter_12
{
 using namespace std;
 // read the input file and build the map of lines to line numbers
 TextQuery::TextQuery(ifstream &is) :file(new vector<string>)
 {
  string text;
  while (getline(is, text))
  {
   // for each line in the file
   (file)->push_back(text); // remember this line of text
   int n = (file)->size() - 1; // the current line number
   istringstream line(text); // separate the line into words
   string word;
   while (line >> word)
   { // for each word in that line
     // if word isn't already in wm, subscripting adds a new entry
    auto &lines = wm[word]; // lines is a shared_ptr
    if (!lines) // that pointer is null the first time we see word
     lines.reset(new set<line_no>); // allocate a new set
    lines->insert(n); // insert this line number
   }
  }
 }
 QueryResult TextQuery::query(const string &sought) const
 { // we'll return a pointer to this set if we don't find sought
  static shared_ptr<set<line_no>> nodata(new set<line_no>);
  // use find and not a subscript to avoid adding words to wm!
  auto loc = wm.find(sought);
  if (loc == wm.end())
   return QueryResult(sought, nodata, file); // not found
  else
   return QueryResult(sought, loc->second, file);
 }
 set<line_no>::iterator QueryResult::begin() const
 {
  return (*lines).begin();
 }
 set<line_no>::iterator QueryResult::end() const
 {
  return lines->end();
 }
 std::shared_ptr<std::vector<std::string>> QueryResult::get_file() const
 {
  return file;
 }
 ostream &print(ostream & os, const QueryResult &qr)
 { // if the word was found, print the count and all occurrences
  os << qr.sought << " occurs " << qr.lines->size() << " " << ((qr.lines->size() > 1) ? "times" : "time") << endl;
  // print each line in which the word appeared
  for (auto num : *qr.lines) // for every element in the set
           // don't confound the user with text lines starting at 0
   os << "\t(line " << num + 1 << ") " << *(qr.file->begin() + num) << endl;
  return os;
 }
}

(iv) query_base_namespace.h, a header file

#pragma once
#ifndef QUERY_BASE_NAMESPACE
#define QUERY_BASE_NAMESPACE
#include<iostream>
#include<vector>
#include<string>
#include<new>
#include<memory>
#include<bitset>
#include<fstream>
#include<sstream>
#include<map>
#include<set>
//#include"Text_Query.h"
#include<algorithm>
#include<iterator>
#include"Textquery_namespace.h"

//using namespace std;

//using namespace chapter_12;
//using chapter_12::TextQuery;
//using chapter_12::QueryResult;
namespace chapter_15
{
 using std::cout;
 using chapter_12::TextQuery;
 using chapter_12::QueryResult;
 // abstract class acts as a base class for concrete query types; all members are private
 class Query_base {
  friend class Query;
 protected:
  //using line_no = TextQuery::line_no; // used in the eval functions
  virtual ~Query_base() = default;
 private: // eval returns the QueryResult that matches this Query
  virtual QueryResult eval(const TextQuery&) const = 0; // rep is a string representation of the query
  virtual std::string rep() const = 0;
 };
 // interface class to manage the Query_base inheritance hierarchy
 class Query { // these operator need access to the shared_ptr constructor
  friend Query operator~(const Query &);
  friend Query operator|(const Query&, const Query&);
  friend Query operator&(const Query&, const Query&);
 public:
  Query(const std::string&); // builds a new WordQuery // interface functions: call the corresponding Query_base operations
  QueryResult eval(const TextQuery &t) const
  {
   return q->eval(t);
  }
  std::string rep() const { cout << "Query rep member"; return q->rep(); }
 private:
  Query(std::shared_ptr<Query_base> query) : q(query) { }
  std::shared_ptr<Query_base> q;
 };
 Query operator~(const Query &);
 Query operator|(const Query&, const Query&);
 Query operator&(const Query&, const Query&);

 class WordQuery : public Query_base {
  friend class Query; // Query uses the WordQuery constructor
  WordQuery(const std::string &s) : query_word(s) { cout << "WordQuery constructor" << query_word; } // concrete class: WordQuery defines all inherited pure virtual functions
  QueryResult eval(const TextQuery &t) const {
   return t.query(query_word);
  }
  std::string rep() const { cout << "WordQuery rep member"; return query_word; }
  std::string query_word; // word for which to search
 };
 class NotQuery : public Query_base {
  friend Query operator~(const Query &);
  NotQuery(const Query &q) : query(q) { cout << "NotQuery constructor"; } // concrete class: NotQuery defines all inherited pure virtual functions
  std::string rep() const
  {
   cout << "NotQuery rep member"; return "~(" + query.rep() + ")";
  }
  QueryResult eval(const TextQuery&) const;
  Query query;
 };
 class BinaryQuery : public Query_base {
 protected:
  BinaryQuery(const Query &l, const Query &r, std::string s) : lhs(l), rhs(r), opSym(s) { cout << "BinaryQuery constructor"; } // abstract class: BinaryQuery doesn't define eval
  std::string rep() const
  {
   cout << "BinaryQuery rep member"; return "(" + lhs.rep() + " " + opSym + " " + rhs.rep() + ")";
  }
  Query lhs, rhs; // right-and left - hand operands
  std::string opSym; // name of the operator
 };
 class AndQuery : public BinaryQuery {
  friend Query operator& (const Query&, const Query&);
  AndQuery(const Query &left, const Query &right) : BinaryQuery(left, right, "&") { cout << "AndQuery constructor"; } // concrete class: AndQuery inherits rep and defines the remaining pure virtual
  QueryResult eval(const TextQuery&) const;
 };
 class OrQuery : public BinaryQuery {
  friend Query operator|(const Query&, const Query&);
  OrQuery(const Query &left, const Query &right) : BinaryQuery(left, right, "|") { cout << "OrQuery constructor"; }
  QueryResult eval(const TextQuery&) const;

 };
}
#endif // ! QUERY_BASE_NAMESPACE

(v) query_base_namespace.cpp, a source file

#include "stdafx.h"
#include "query_base_namespace.h"
//#include "Textquery_namespace.h"
//using namespace std;
//using namespace chapter_12;

namespace chapter_15
{
 
 //using namespace chapter_12;
 using std::set;
 using std::make_shared;
 typedef std::vector<std::string>::size_type line_no;
 using chapter_12::QueryResult;
 std::ostream & operator<<(std::ostream &os, const Query &query)
 { // Query::rep makes a virtual call through its Query_base pointer to rep()
  return os << query.rep();
 }
 inline Query::Query(const std::string &s) : q(new WordQuery(s)) { cout << "Query constructor"; }
 inline Query operator~(const Query &operand) {
  return std::shared_ptr<Query_base>(new NotQuery(operand));
 }
 
 inline Query operator|(const Query &lhs, const Query &rhs)
 {
  return std::shared_ptr<Query_base>(new OrQuery(lhs, rhs));
 }
 inline Query operator&(const Query &lhs, const Query &rhs) {
  return std::shared_ptr<Query_base>(new AndQuery(lhs, rhs));
 }

 // returns the union of its operands' result set s
 QueryResult OrQuery::eval(const TextQuery& text)const
 { // virtual calls through the Query members, lhs and rhs // the calls to eval return the QueryResult for each operand
  auto right = rhs.eval(text), left = lhs.eval(text); // copy the line numbers from the left - hand operand into the result set
  auto ret_lines = make_shared<set<line_no>>(left.begin(), left.end());
  // insert lines from the right-hand operand
  ret_lines->insert(right.begin(), right.end()); // return the new QueryResult representing the union of lhs and rhs
  return QueryResult(rep(), ret_lines, left.get_file());
 }
 // returns the intersection of its operands' result set s
 QueryResult AndQuery::eval(const TextQuery& text) const
 { // virtual calls through the Query operands to get result set s for the operands
  auto left = lhs.eval(text), right = rhs.eval(text); // set to hold the intersection of left and right
  auto ret_lines = make_shared<set<line_no>>(); // writes the intersection of two ranges to a destination iterator // destination iterator in this call adds elements to ret
  set_intersection(left.begin(), left.end(), right.begin(), right.end(), inserter(*ret_lines, ret_lines->begin()));
  return QueryResult(rep(), ret_lines, left.get_file());
 }
 // returns the lines not in its operand's result set
 QueryResult NotQuery::eval(const TextQuery&text) const
 { // virtual call to eval through the Query operand
  auto result = query.eval(text); // start out with an empty result set
  auto ret_lines = make_shared<set<line_no>>(); // we have to iterate through the lines on which our operand appears
  auto beg = result.begin(), end = result.end(); // for each line in the input file, if that line is not in result, // add that line number to ret_lines
  auto sz = result.get_file()->size();
  for (size_t n = 0; n != sz; ++n)
  { // if we haven't processed all the lines in result
    // check whether this line is present
   if (beg == end || *beg != n)
    ret_lines->insert(n);
   // if not in result, add this line
   else if (beg != end)
    ++beg; // otherwise get the next line number in result if there is one
  }
  return QueryResult(rep(), ret_lines, result.get_file());
 }
}

thanks for reading up to here. your help will be highly appreciated


how to set parent to desktop window

$
0
0

Hi, I am trying to use setparent point to the desktop window, is there any samples? I failed in creating in this way


m_bannerTop->SetParent(GetDesktopWindow())

samples about popup dialog resize and move as main dialog resize and move

$
0
0

Hi, I checked other resources regarding this, but quite limited. Is there any sample regarding popup dialog resize and move as main dialog resize and move?

Thanks

Where can I find Direc3D9Ex and DXGI Interop Helper and Sample ?

$
0
0

Hi,

I'm searching for the "Direc3D9Ex and DXGI Interop Helper and Sample" referenced on the MSDN article "Surface Sharing Between Windows Graphics APIs" . All urls related to D3D9ExDXGISharedSurf are redirected to a page telling "The archive gallery has been retired".

Is there anywhere else I could get this sample ?

Thanks

Dialog based MFC exe not being able to run!!

$
0
0

Hi,

I have an MFC exe that is dialog based, but that for some reason (don't know what I changed) it is not being able to DoModal().

On the application's InitInstance() this happens:

	CGridCtrlDemoDlg dlg;
	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
	}
	else if (nResponse == IDCANCEL)
	{
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;

nResponse returns IDCANCEL.

On the creation of the CDialog, MAKEINTRESOURCE(nIDTemplate) returns a pointer which does not allow to read the charatacters...

So, it might be a resource problem??

Can I share it in OneDrive?

Regards,

Juan


Juan Dent

Get Computer Users Directory Path (as a String)

$
0
0

Programming Setup: C++, MFC, Unicode, single byte character set
Programming with: VS 2015 

Computer: Windows 10

Issue:

I need to get the path of the Users executing this application.

Example:  C:\Users\joliv\...

I need a function that returns "joliv" (or I could also get "C:\Users\joliv".  I don't know if I'm using the correct terms or not so let me tell you what I've done.  I started using: GetComputerName(infoBuf, &bufCharCount). This was an obvious wrong. 

TCHAR  infoBuf[INFO_BUFFER_SIZE];
DWORD  bufCharCount = INFO_BUFFER_SIZE;

if (!GetComputerName(infoBuf, &bufCharCount))
   return false;

... Do Work ...

then GetUserName(infoBuf, &bufCharCount)

char szUser[50]; char* pTemp = NULL; memset(szUser, 0, sizeof(szUser)); pTemp = _dupenv_s(szUser("USER")); if (pTemp != 0) { strncpy(szUser, pTemp, sizeof(szUser)); pTemp = NULL; } .... Do other work .....

I haven't coded in 10 years so I'm rusty The code above gives me errors. My understanding is that programmers no longer use "char" like the old days.
so I get confused if I should always use TCHAR. My understanding is that it is better to use single byte character
set


What is strange is that... GetUserName( ifoBuf, &bufCharCount) works on one computer (laptop) but not on my Test computer (both running win 10. This is baffling.  The code below can work if "rfid" = "FOLDERID_AccountPictures" which gives me a super long string. I could manipulate the string to get everything up to the second "\\" (slash).  But that seems like a hokey way to code.

if (E_FAIL == SHGetKnownFolderPath(rfid, 0, NULL, ppszPath)) { MessageBox(_T("SHGetKnownFolderPath Error")); return false; }

.... Do other work ....

Any help is appreciated.  Thanks



JCO


Is there a modern compiler compatible with Python24

$
0
0

I'm working with a large old dll which uses Python24 and Boost-1.32.0. The makefile uses the Microsoft Visual C++ Toolkit 2003 cl.exe which works but it would be nice to go with C++ 11 and more modern secure functions. Every other compiler I've tried to date does not like the fact that there are variables which are not declared. Below is an example of what I mean:

1>CvGameInterface.cpp(1997): error C2065: 'iI' : undeclared identifier

aFlyoutItems.push_back(CvFlyoutMenuData(FLYOUT_CONSCRIPT, iI, pPlot->getX_INLINE(), pPlot->getY_INLINE(), szBuffer));

Changing things would take considerable time so is there either a compiler which is compatible with Python24, which I can use with the makefile or is there a way to make modern compilers ignore the undeclared variables? I'd be grateful for any help.

Thanks, Chris.


MFC Desktop application with "advanced" touch / pen support

$
0
0

Hello

I have the followed Problem. I have a MFC Desktop application running under Windows 10 and I'd like to improve the touch / pen capabilities.

Windows 10 itself and also i.e. the file Explorer Supports in a good way the touch / pen capailities. When I touch the Screen and keep the finger on the Screen a surrounding square is displayed. If the square is displayed I know if I remove the finger a context menu will be displayed.

The same with the pen capabilities. I Keep the pen on the Screen, the Little circle will Close, if I than remove the pen the context menu is displayed.

I am assuming this is a General Windows functionality. I tried RegisterTouchWindow, but the square for touch and the circle for pen events does not Show up. Is there a Special API to have this Feature or what am I missing? Most Microsot Desktop applications have this Feature. Also Notepad Supports this.

My question is how can I implement the above described Feature?


Best regards

Bordon

Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.



I don't understand what is wrong with these C++ codes

$
0
0

LinkedList.h

#pragma once
template<typename Type>
class LinkedList
{
	private:
		struct Node
		{
			Type item;
			Node* next;
			Node(const Type&);
			Node(const Type&,Node*);
			~Node();
			void* operator new(size_t);
			void operator delete(void*);
		};
		Node* pointer;
	public:
		class Iterator
		{
			private:
				Node* pointer;
			public:
				Iterator(LinkedList&);
				bool operator++();
				Type& operator*();
				Type& operator->();
				operator Type*();
				operator bool();
		};
		LinkedList();
		bool Add(const Type&);
		bool Remove(const Type&);
		bool Delete(const Type&);
		Iterator Begin(); //The syntax error I get relates to this line
		~LinkedList();
};

LinkedList.cpp

#include "stdafx.h"
#include "LinkedList.h"

template<typename Type>
LinkedList<Type>::LinkedList() : pointer(nullptr) {}

template<typename Type>
LinkedList<Type>::~LinkedList()
{
	if (this->pointer != nullptr)
		delete this->pointer;
}

template<typename Type>
bool LinkedList<Type>::Add(const Type& item) { return this->pointer = new Node(item,this->pointer); }

template<typename Type>
LinkedList<Type>::Iterator::Iterator(LinkedList<Type>& l) : pointer(l.pointer) {}

template<typename Type>
LinkedList<Type>::Iterator LinkedList<Type>::Begin() { return Iterator(this->pointer); } //The syntax error I get relates to this line

For these codes above I get this:

syntax error: identifier 'Iterator'

What's the problem C++ compiler? I have already defined this class inside LinkedList class, which I also defined in LinkedList.h, and I #include it here in LinkedList.cpp. Are you trying to tell me that 'Iterator' is undefined or what else? I don't understand you please explain already!

DLL error message is corrupted

$
0
0

My code formats a message for when a dll cannot be loaded.

    dllMod = LoadLibrary(_T( "USERDLL.dll" ));
    
    if ( dllMod != NULL ) {    // load for all processes
        userdllinit( );
    } else {

        LPVOID lpMsgBuf;
        LPVOID lpDisplayBuf;
        DWORD dw = GetLastError();

        FormatMessage(
            FORMAT_MESSAGE_ALLOCATE_BUFFER |
            FORMAT_MESSAGE_FROM_SYSTEM |
            FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL,
            dw,
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
            (LPTSTR) &lpMsgBuf,
            0, NULL );

        // Display the error message

        lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
            (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)LoadLibrary) + 40) * sizeof(TCHAR));
        StringCchPrintf((LPTSTR)lpDisplayBuf,
            LocalSize(lpDisplayBuf) / sizeof(TCHAR),
            TEXT("%s failed with error %d: %s"),
            LoadLibrary, dw, lpMsgBuf);
        MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);

        LocalFree(lpMsgBuf);
        LocalFree(lpDisplayBuf);

    }
If there is no dll available, it gives this message:

How can I get rid of all the garbage?  I only want the message itself.

Point at which MFC application finished initializing

$
0
0

Guys,

Where/what is the point at which MFC application finished everything with regards to initializing/loading itself and it is awaiting for input from the user?

Is there a method which indicates that state has been reached?

Thank you

Visual C++ 2015 Redistributable (x64) 14.0.23026 Error

$
0
0
I get 0x80240017 Unspecified error.  Error log shows error Error 0x80240017: Failed to execute MSU package.  I've found a lot of info on this, but only fixes for x86.  Some things I've tried but have not helped: System File Checker (ok), Download in Clean boot (same error).  Tried to install KB2999226, but that is not applicable for my windows 7 64bit machine.  After I install c++ 2015, windows updater says I need to install 10 new files, I install, but then get wiped out upon installing c++ 2015.   Any help would be appreciated.

Using WinInet to update database

$
0
0

I want to update a MySql database from a Windows application that is written in Visual C++. I have used the article "How to simulate a Form POST request by using WinInet" for guidance and changed it to the GET request. There were no updates made to the database.  I changed the code to use the localhost for test purposes. 

void COnlineProView::HTTPFormGetRequest(CString szFormData)
{
	CString szHeaders =
		_T("Content-Type: application/x-www-form-urlencoded");
	CInternetSession session;
	CHttpConnection* pConnection =
		session.GetHttpConnection(_T("localhost"));
	CHttpFile* pFile =
		pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,
			_T("localhost/aws.php"));
	BOOL result = pFile->SendRequest(szHeaders, (LPVOID)(LPCSTR)szFormData, szFormData.GetLength());
}

My aws.php is a simple program that prints the $_GET array. When I run my application, I don't get to see any output from aws.php in my browser. I will say that I am a complete novice at passing data via the internet so I'm not completely sure that I'm looking in the right area. I would appreciate any advice. Many thanks. 


High DPI with checkboxes and radio butttons

$
0
0

I have a large MFC application that I have made High DPI aware.  I have all my windows and dialogs scaling based on the dpi of the monitor they are being displayed.  The windows 10 anniversary update helped with things like non client scaling, but I have some big issues with checkboxes and radio buttons.  The fonts on these controls have been scaled correctly. but the glyphs for the square or circle are either too large or too small.  If the main display is at 250% (4k) and another display is at 100% the checkbox square is WAY too big on the other display on both windows and dialogs.  If the main and other display scale factor is switched, then the checkbox square is too small.

Is there something I can do in my application or is this glyph drawing totally an issue with Windows itself or is it an issue that needs to be solved by Microsoft?

Reference articles used:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266(v=vs.85).aspx

https://blogs.technet.microsoft.com/askcore/2015/12/08/display-scaling-in-windows-10/

https://blogs.windows.com/buildingapps/2016/10/24/high-dpi-scaling-improvements-for-desktop-applications-and-mixed-mode-dpi-scaling-in-the-windows-10-anniversary-update/#Hra3ASt46fOszMRg.97

Thanks

Microsoft Flgt X Sim-Gold Edition

$
0
0
Age 77,not computer savey so please be specific if you have a solution or explanation; 1. Have HP-Model P7-1166/AMD A6-3650 APU/RADEON (TM)HD/GRAPHICS 2.60GHZ/64 bIT MSYSX64 Processor. I installed all three disks, prog worked fine 1st time after that I now get ERROR,Message everytime I START PROGRAM---iTS  1-80004605. If I ignore Flight Sim will still load and play but Is there a way to fix this error message.  "Thank You" Sam  

DLL not found on tablet computer

$
0
0

My dll loads and runs perfectly on a desktop and laptop PC.  When my customer tries to run it on a tablet PC, the LoadLibrary() function comes back with error 126, module not found.  His configuration is

Windows 10 Home

Version 1511

OD Build 10586.589

...

Processor x5-Z8300 CPU...

Ram 2.00 GB

System type 64-bit, x64 processor

The dll was compiled on a 32-bit OS.  Could that be the problem?  I know you can't go the other way.

Can you figure out why this will not load?

Visual Studio 2017 Form Designer failure

$
0
0

Hi, All

Was not sure where to post this so here it is ...

Select: File:New:Project
Select: Installed:Templates:Visual C++:CLR:CLR Empty Project

Wait for it to load ... And some!

In Solution Explorer, Right Click the Project.
  Select: Add:New ITem
  Select: Installed:Visual C++:UI:Windows Form
  Select: Add

KaBoom ... The data necessary to complete this operation is not yet availiable. (Exception from HRESULT: 0x8000000A)

From this point forward, the Designer is gone ... Restart VStudio (even OS), Re open the project and no designer.

Is there a solution.

The form .h file:

#pragma once

namespace Deleteme {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for MyForm
	/// </summary>
	public ref class MyForm : public System::Windows::Forms::Form
	{
	public:
		MyForm(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MyForm()
		{
			if (components)
			{
				delete components;
			}
		}

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = gcnew System::ComponentModel::Container();
			this->Size = System::Drawing::Size(300,300);
			this->Text = L"MyForm";
			this->Padding = System::Windows::Forms::Padding(0);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
		}
#pragma endregion
	};
}

EDIT: ooPs, Sorry, forgot os: Win7

Thank you
-Enjoy
fh : )_~


Can My App Know A Dialog Has Been Repainted?

$
0
0

Hi Folks:

   Developing on Windows 10 Pro, Visual Studio 2015 Community, all C++.

   Is there some way to inform a dialog procedure that the repaint initiated by the dialog procedure's WM_PAINT message has finished? 

   I've tried posting a message of mine to the dialog at the end of the WM_PAINT clause, hoping the dialog would receive it after the repaint was finished, but the dialog receives it before the dialog is repainted.  

   I've looked, but haven't found a message the system sends to my dialog informing it that the repaint is finished. 

      Thanks
      Larry


Viewing all 15302 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>