| | |
vector <char*>
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 9
Reputation:
Solved Threads: 0
Hi, i have a problem with a vector.
I declare a vector<char*> moves; in header.
Code:
Thank You.
I declare a vector<char*> moves; in header.
Code:
C++ Syntax (Toggle Plain Text)
void LogView::init(){ int a = 0; while (LogFile.good()){ LogFile.getline(line, 6); moves.push_back(line); cout << "vector :"<< moves[a]<< endl; // here is OK a++; } moves.begin(); cout << "vektor :"<< moves[1]<< endl; // here is NOT OK cout << "vektor :"<< moves[2]<< endl; // here is NOT OK cout << "vektor :"<< moves[3]<< endl; // here is NOT OK cout << "vektor :"<< moves.at(1)<< endl; // here is NOT OK cout << "vektor :"<< moves.at(2)<< endl; // here is NOT OK cout << "vektor :"<< moves.at(3)<< endl; // here is NOT OK cout << "vektor :"<< moves.front()<< endl; // here is NOT OK cout << "vektor :"<< moves.back()<< endl; // here is NOT OK //AN ITERATION FOR IS NOT OK TOO. cout << moves.size(); // IT'S OK! } }
Thank You.
•
•
Join Date: Oct 2008
Posts: 9
Reputation:
Solved Threads: 0
Hi, in header:
C++ Syntax (Toggle Plain Text)
private: std::ifstream LogFile; char line[5]; std::vector<char*> moves;
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
When you append pointers onto a vector of char, the pointer is copied. You are expecting the data the pointer points at to be copied.
With a vector<char *> you need to explicitly copy the data as well as the pointer.
An easier way would be to use a std::vector<std::string> instead (as std::string objects copy the data implicitly).
With a vector<char *> you need to explicitly copy the data as well as the pointer.
An easier way would be to use a std::vector<std::string> instead (as std::string objects copy the data implicitly).
![]() |
Similar Threads
- Large Char Array (C++)
- How to convert a vector<int> to vector<string> (C++)
- C and C++ Timesaving Tips (C++)
- passing a vector to a function? :errors: (C++)
- Errors writing a vector to a file (C++)
- Random Characters (C++)
- can a vector take array of char(char *) (ASP.NET)
Other Threads in the C++ Forum
- Previous Thread: C++ Newbie
- Next Thread: Matrix
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





