Click here to Skip to main content
16,011,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CString concatenation problem Pin
Arman S.13-Jun-07 6:18
Arman S.13-Jun-07 6:18 
GeneralRe: CString concatenation problem Pin
penny black14-Jun-07 3:34
penny black14-Jun-07 3:34 
QuestionRe: CString concatenation problem Pin
David Crow13-Jun-07 6:21
David Crow13-Jun-07 6:21 
AnswerRe: CString concatenation problem Pin
penny black14-Jun-07 3:36
penny black14-Jun-07 3:36 
Questionproblem with ifstream Pin
Yonggoo13-Jun-07 5:42
Yonggoo13-Jun-07 5:42 
AnswerRe: problem with ifstream Pin
David Crow13-Jun-07 5:57
David Crow13-Jun-07 5:57 
GeneralRe: problem with ifstream(more details?) Pin
Yonggoo13-Jun-07 6:03
Yonggoo13-Jun-07 6:03 
GeneralRe: problem with ifstream(more details?) Pin
David Crow13-Jun-07 6:16
David Crow13-Jun-07 6:16 
Yonggoo wrote:
Does std c++ have iterator?


Yes.

class LineItem
{
public:
    LineItem() {}
    ~LineItem() {}
 
    void setLength(const int length) { _Length = length; }
    int getLength() const { return _Length; }
 
    void setNumbers(const std::vector<int>& numbers) { _Numbers.assign(numbers.begin(), numbers.end()); }
    std::vector<int> getNumbers() const { return _Numbers; }
private:
    int _Length;
    std::vector<int> _Numbers;
};
 
std::ostream& operator<<(std::ostream& os, const LineItem& s)
{
    os << s.getLength() << "|";
 
    const std::vector<int> numbers = s.getNumbers();
    std::copy(numbers.begin(), numbers.end(), std::ostream_iterator<int>(os, " "));
	
    os << std::endl;
	
    return os;
}
 
std::istream& operator>>(std::istream& is, LineItem& s)
{
    int length;
    is >> length;
 
    std::string sNumbers = "";
    std::getline(is, sNumbers);
 
    std::stringstream ss(sNumbers);
 	
    std::vector<int> numbers;
    std::copy(std::istream_iterator<int>(ss), std::istream_iterator<<int>(), std::back_inserter(numbers));
    
    s.setLength(length);
    s.setNumbers(numbers);
	
    return is;
}
 
void main( void )
{
    std::ifstream fin;
    std::vector<LineItem> lines;
	
    fin.open("c:\\input.txt");
    std::copy(std::istream_iterator<LineItem>(fin), std::istream_iterator<LineItem>(), std::back_inserter(lines));
    fin.close();
 
    std::copy(lines.begin(), lines.end(), std::ostream_iterator<LineItem>(std::cout, "\n"));
}




"A good athlete is the result of a good and worthy opponent." - David Crow

"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne


QuestionVisual Studio debugger telling me wrong information Pin
Cyrilix13-Jun-07 5:35
Cyrilix13-Jun-07 5:35 
QuestionRe: Visual Studio debugger telling me wrong information Pin
David Crow13-Jun-07 6:19
David Crow13-Jun-07 6:19 
AnswerRe: Visual Studio debugger telling me wrong information Pin
Cyrilix13-Jun-07 6:35
Cyrilix13-Jun-07 6:35 
AnswerProblem Fixed -- optimization (/O2) causes these problems Pin
Cyrilix13-Jun-07 6:49
Cyrilix13-Jun-07 6:49 
GeneralRe: Problem Fixed -- optimization (/O2) causes these problems Pin
David Crow13-Jun-07 6:53
David Crow13-Jun-07 6:53 
GeneralRe: Problem Fixed -- optimization (/O2) causes these problems Pin
Cyrilix13-Jun-07 7:02
Cyrilix13-Jun-07 7:02 
Questionutyutyuytuutyutyutyuutyutyutyutyutyutyu/,.//,./, Pin
suchon_phuong13-Jun-07 5:33
suchon_phuong13-Jun-07 5:33 
AnswerRe: utyutyuytuutyutyutyuutyutyutyutyutyutyu/,.//,./, Pin
Cedric Moonen13-Jun-07 7:11
Cedric Moonen13-Jun-07 7:11 
QuestionDraw a cube Pin
gentleguy13-Jun-07 5:18
gentleguy13-Jun-07 5:18 
AnswerRe: Draw a cube Pin
Dustin Henry13-Jun-07 6:51
Dustin Henry13-Jun-07 6:51 
QuestionOnMouseMove HELP Please Pin
Charlie Curtis13-Jun-07 3:39
Charlie Curtis13-Jun-07 3:39 
AnswerRe: OnMouseMove HELP Please [modified] Pin
Mark Salsbery13-Jun-07 7:19
Mark Salsbery13-Jun-07 7:19 
QuestionC++ Thread Memory States/References Pin
Eshazear13-Jun-07 3:36
Eshazear13-Jun-07 3:36 
AnswerRe: C++ Thread Memory States/References Pin
James R. Twine13-Jun-07 3:46
James R. Twine13-Jun-07 3:46 
GeneralRe: C++ Thread Memory States/References Pin
Eshazear13-Jun-07 4:13
Eshazear13-Jun-07 4:13 
GeneralRe: C++ Thread Memory States/References Pin
Roger Stoltz13-Jun-07 4:35
Roger Stoltz13-Jun-07 4:35 
GeneralMultithreaded aproaches Pin
Eshazear13-Jun-07 4:45
Eshazear13-Jun-07 4:45 

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.