Search:

Type: Posts; User: grib

Page 1 of 13 1 2 3 4

Search: Search took 0.02 seconds; generated 9 minute(s) ago.

  1. Thread: Sum of numbers

    by grib
    Replies
    3
    Views
    1,483

    std::cout

    std::cout << (Number*(Number+1)/2) << std::endl;


    :)

    or, if you want to learn programming, consider two loops. I am going to write the outer loop for you, because this is a good habit to get...
  2. Replies
    6
    Views
    2,445

    Your best bet is to go ahead and give a...

    Your best bet is to go ahead and give a meaningful name to the test, even if it's just is_valid(). This makes things easier to read and maintain. If you really want to have that magic test, write a...
  3. copy(std::istream_iterator(file),...

    copy(std::istream_iterator<std::string>(file), istream_iterator<std::string>(), std::back_inserter(vec));

    Back_inserter works fine for anything that has a .push_back()
  4. Replies
    7
    Views
    2,260

    The other option is to use std::getline(std::cin...

    The other option is to use std::getline(std::cin >> std::ws, name); What this gets is a single line, not including terminator '\n', where the terminator is consumed, with no leading whitespace. This...
  5. "Premature optimization is the root of all evil"...

    "Premature optimization is the root of all evil"
    -- Donald Kunth

    One of vectors tricks is that excess capacity is uninitialized. what this means is that the os will never have to allocate any...
  6. Thread: Arrays & Classes

    by grib
    Replies
    6
    Views
    1,230

    x=0; is perfectly allowable inside a constructor,...

    x=0; is perfectly allowable inside a constructor, the problem is that inside the body of a constructor it's assignment, rather than construction. the correct way of doing this is ctor() : x(0), ......
  7. when gWornArmorTravelersHead falls out of scope...

    when gWornArmorTravelersHead falls out of scope wornhead is pointing to undefined behavior. I don't see any reason that wornhead needs to be a pointer.

    Prefixing an & to a variable returns the...
  8. Replies
    9
    Views
    2,679

    If your files are text you can also improve...

    If your files are text you can also improve performance by writing a preprocessing step that will convert your text files into something like


    struct element {
    int x,y,z;
    float value;...
  9. Replies
    5
    Views
    1,653

    template bool parse(T &e, const...

    template<class T>
    bool parse(T &e, const std::string &s) {
    std::istringstream iss(s);
    return (iss >> e) && iss.eof();
    // or, to accept trailing whitespace
    return (iss >> e >>...
  10. Thread: i'm stuck

    by grib
    Replies
    2
    Views
    954

    sqm_ is a pointer to an array of segments, to...

    sqm_ is a pointer to an array of segments, to read or write all segments you will need to loop from sqm_[0] to sqm_[count_-1] and perform the correct operation on each. The C++ way to do this is to...
  11. Replies
    10
    Views
    3,012

    you can of course do this int rmain(int argc,...

    you can of course do this

    int rmain(int argc, char *argv[]) {
    // recursive whatever goes here
    }
    int main(int argc, char *argv[]) {return rmain(argc,argv);}

    I am really not sure why you would...
  12. Replies
    4
    Views
    985

    I don't see where you are incrementing i, which...

    I don't see where you are incrementing i, which appears to be a global. You also don't appear to have a need for a string stream at all.
    fileout << TD[i].X << ", " << TD[i].Y << '\n'; will write...
  13. Replies
    2
    Views
    1,562

    Actually what volatile does is more like forces...

    Actually what volatile does is more like forces the compiler to allocate ordinary memory for a variable and to assume nothing when working with the variable. const volatile is really only used for...
  14. Replies
    2
    Views
    4,216

    It's by no means a trivial problem, the general...

    It's by no means a trivial problem, the general field is known as Computer Vision, with your particular problem known as scene reconstruction. Most problems involving multiple images and scene...
  15. Replies
    7
    Views
    4,699

    Another common variant to take care of newlines...

    Another common variant to take care of newlines in the input is


    if(std::getline(std::cin >> std::ws,line) {
    // Process line
    }
    std::ws is a manipulator that accepts only whitespace. You can...
  16. Replies
    1
    Views
    960

    binTree needs to be able to see the definitnion...

    binTree needs to be able to see the definitnion of binTNode(), not just the prototype. Thus


    template<class T>
    binTNode<T>::binTNode(const T& d=T(), binTNode<T>* l=0, binTNode<T>* r=0) :...
  17. Replies
    5
    Views
    1,594

    samp in your class is a stream varable, streams...

    samp in your class is a stream varable, streams are, in general, non-copyable. The normal way to design something like this is to have a friend >> operator.


    class Crypt {
    ...
    friend...
  18. Replies
    7
    Views
    1,770

    cout > data) { ...

    cout << "Enter data: ";
    while(cin >> data) {
    if(valid) {
    } else break;
    cout << "Enter data: ";
    }
  19. Replies
    21
    Views
    20,542

    The getline version that works with strings is a...

    The getline version that works with strings is a free function


    std::string str;
    std::getline(std::cin,str);

    Note also the the pointer returned by c_str() is only good so long as the...
  20. Replies
    11
    Views
    6,151

    std::istringstream iss(myString); int n; if(iss...

    std::istringstream iss(myString);
    int n;
    if(iss >> n && iss.eof()) {
    // myString is a properly formated number with no trailing characters or whitespace
    // leading whitespace is ignored
    }...
  21. Replies
    4
    Views
    1,272

    (a/b)*b + a % b = a Or with decimals 14.8 is...

    (a/b)*b + a % b = a
    Or with decimals
    14.8 is equal to 14 and eight tenths, eight is not the remainder of anything.
    Eight tenths is equal to 4/5, that is the remander(4 or 74 % 5) divided by 5....
  22. Replies
    15
    Views
    2,067

    well .substr works on strings, but strlen() works...

    well .substr works on strings, but strlen() works on char *'s. The std::string equivilent to strlen() is s.length() or s.size(). Your code confused me, so I am just going to give you the stl style...
  23. Replies
    2
    Views
    1,798

    This is a good case study in why human readable...

    This is a good case study in why human readable file formats are nice. My guess would be that bin_read_string goes too far and consumes some of your stat data.
  24. Replies
    6
    Views
    1,070

    You can pass streams around by reference...

    You can pass streams around by reference relatively freely, however this may not be quite what you want. If you want to search in a stream/file for a particular string you could do something like...
  25. These are not the same things, although they all...

    These are not the same things, although they all "work". Part of the joy and problem with c is that it's so easy to get confused. Pointers and arrays can usually be interchanged freely.

    char...
Results 1 to 25 of 312
Page 1 of 13 1 2 3 4