Click here to Skip to main content
15,799,398 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What IDE is good for developing GUI apps using C++? Pin
Calin Negru29-May-22 9:34
Calin Negru29-May-22 9:34 
AnswerRe: What IDE is good for developing GUI apps using C++? Pin
Joe Woodbury29-May-22 14:44
professionalJoe Woodbury29-May-22 14:44 
AnswerRe: What IDE is good for developing GUI apps using C++? Pin
Richard MacCutchan29-May-22 23:12
mveRichard MacCutchan29-May-22 23:12 
AnswerRe: What IDE is good for developing GUI apps using C++? Pin
Gerry Schmitz30-May-22 7:12
mveGerry Schmitz30-May-22 7:12 
Questionvector and Template confusion Pin
T Bones Jones23-May-22 8:33
T Bones Jones23-May-22 8:33 
AnswerRe: vector and Template confusion Pin
Victor Nijegorodov23-May-22 9:09
Victor Nijegorodov23-May-22 9:09 
GeneralRe: vector and Template confusion Pin
T Bones Jones23-May-22 9:12
T Bones Jones23-May-22 9:12 
AnswerRe: vector and Template confusion Pin
CPallini23-May-22 23:02
mveCPallini23-May-22 23:02 
Probably there is part of your code (not posted here) messing up with the Subtraction vector.
This code
C++
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

template < typename T1, typename T2 >
void printvector(T1& fout, const std::vector < T2 >& V)
{
    if (V.empty()) fout << "EMPTY\n";
    else {
        for (size_t x = 0; x != V.size() - 1; ++x)
        {
           fout << V[x] << ", ";
        }
        fout << V[V.size() - 1] << '\n';
    }
}


int main()
{
  vector <size_t> sub {46,47,48};

  printvector(cout, sub);
  fstream foofile("foo.txt", ios::out);
  if (foofile)
  {
    printvector(foofile, sub);
  }
}
produces the same output
46, 47, 48
both to the console and to the foo.txt file.


[update]
Note, you might also write
C++
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

template <typename T>
ostream & operator<< (ostream & os, const vector <T> & v)
{
  if ( v.empty() ) os << "EMPTY\n";
  else
  {
    for (size_t n = 0; n != v.size() - 1; ++n)
    {
      os << v[n] << ", ";
    }
    os << v.back() << '\n';
  }
  return os;
}

int main()
{
  vector <size_t> sub {46,47,48};

  cout << sub;
  fstream foofile("foo.txt", ios::out);
  if (foofile)
  {
    foofile << sub;
  }
}
[/update]
"In testa che avete, Signor di Ceprano?"
-- Rigoletto


modified 24-May-22 6:02am.

GeneralRe: vector and Template confusion Pin
T Bones Jones24-May-22 5:24
T Bones Jones24-May-22 5:24 
GeneralRe: vector and Template confusion Pin
CPallini24-May-22 21:02
mveCPallini24-May-22 21:02 
AnswerRe: vector and Template confusion Pin
Richard MacCutchan23-May-22 23:03
mveRichard MacCutchan23-May-22 23:03 
GeneralRe: vector and Template confusion Pin
T Bones Jones24-May-22 5:33
T Bones Jones24-May-22 5:33 
GeneralRe: vector and Template confusion Pin
Richard MacCutchan24-May-22 6:02
mveRichard MacCutchan24-May-22 6:02 
GeneralRe: vector and Template confusion Pin
T Bones Jones24-May-22 6:08
T Bones Jones24-May-22 6:08 
GeneralRe: vector and Template confusion Pin
Richard MacCutchan24-May-22 6:11
mveRichard MacCutchan24-May-22 6:11 
QuestionApplication check for virus Pin
Gopi Nath23-May-22 2:18
Gopi Nath23-May-22 2:18 
AnswerRe: Application check for virus Pin
Richard MacCutchan23-May-22 2:25
mveRichard MacCutchan23-May-22 2:25 
AnswerRe: Application check for virus Pin
Dave Kreskowiak23-May-22 3:16
mveDave Kreskowiak23-May-22 3:16 
AnswerRe: Application check for virus Pin
Gopi Nath23-May-22 19:30
Gopi Nath23-May-22 19:30 
QuestionSetting Font and Text Colors items of ComboBox Pin
ForNow22-May-22 13:32
ForNow22-May-22 13:32 
AnswerRe: Setting Font and Text Colors items of ComboBox Solved almost Pin
ForNow22-May-22 14:28
ForNow22-May-22 14:28 
GeneralRe: Setting Font and Text Colors items of ComboBox Solved almost Pin
Victor Nijegorodov22-May-22 21:14
Victor Nijegorodov22-May-22 21:14 
GeneralRe: Setting Font and Text Colors items of ComboBox Solved almost Pin
ForNow22-May-22 23:26
ForNow22-May-22 23:26 
QuestionAccessing and displaying semaphore count Pin
coco24322-May-22 2:42
coco24322-May-22 2:42 
AnswerRe: Accessing and displaying semaphore count Pin
Mircea Neacsu22-May-22 3:02
Mircea Neacsu22-May-22 3:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.