Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #85700 > unrolled thread
| Started by | Jivanmukta <jivanmukta@poczta.onet.pl> |
|---|---|
| First post | 2022-07-27 20:58 +0200 |
| Last post | 2022-07-27 13:05 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.c++
string array demaged at unknown moment Jivanmukta <jivanmukta@poczta.onet.pl> - 2022-07-27 20:58 +0200
Re: string array demaged at unknown moment Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-07-27 13:05 -0700
| From | Jivanmukta <jivanmukta@poczta.onet.pl> |
|---|---|
| Date | 2022-07-27 20:58 +0200 |
| Subject | string array demaged at unknown moment |
| Message-ID | <tbs1si$2pq4g$1@portraits.wsisiz.edu.pl> |
I am writing second time because I don't see my post.
I have an object of class source_file:
class source_file {
private:
std::wstring source_file_path;
int current_source_line_no;
bool inside_php, start_inside_php;
int num_source_lines, too_long_line_number;
std::vector<std::string> source_lines;
std::vector<std::pair<int, std::string>> tokenized_lines;
std::vector<std::pair<int, std::string>>::const_iterator
current_tokenized_lines_iter;
size_t max_line_len, too_long_line_len, max_found_line_len;
public:
source_file(size_t max_line_length = 0) { // 0 means 'no limit'
max_line_len = max_line_length;
too_long_line_len = 0;
max_found_line_len = 0;
current_source_line_no = -1;
num_source_lines = 0;
current_tokenized_lines_iter = tokenized_lines.end();
too_long_line_number = 0;
inside_php = start_inside_php = false;
}
size_t get_max_found_line_length() const {
return max_found_line_len;
}
size_t get_too_long_line_length() const {
return too_long_line_len;
}
int get_too_long_line_number() const {
return too_long_line_number;
}
bool open(std::wstring in_file_path);
void close() {
source_lines.clear();
tokenized_lines.clear();
too_long_line_len = 0;
max_found_line_len = 0;
num_source_lines = 0;
current_source_line_no = -1;
}
void rewind() { // go to begin of file
current_source_line_no = -1;
current_tokenized_lines_iter = tokenized_lines.begin();
inside_php = start_inside_php = false;
}
bool get_next_line(std::string &line);
bool change_current_line(std::string line, bool ltrim_line);
void ltrim_current_line();
void get_contents(std::vector<std::string> &contents);
bool change_file_with_contents(const std::vector<std::string>
&contents, unsigned int defines_line_num = 0, unsigned int
defines_num_lines = 0);
void remove_magic_str(); // obejście dla problemu pozostających
magic_str
void write(std::wstring out_file_path) const {
std::ofstream out_file(shortwstr2str(out_file_path));
for (std::string line : source_lines) {
out_file << line << std::endl;
}
}
void tokenize_file(std::string token_name_delim_str);
bool get_next_line_with_tokenized(std::string &line, std::string
&tokenized_line);
};
Although the file is loeaded correctly by method open(), I have a
problem of spoilt string in source_lines[813], I mean get_next_line()
returns spoilt line. I don't know the moment of time source_lines[813]
is demaged - I use VSCodium but conditional breakpoints don't work.
Please help: how to get the point in code at which source_lines[813] is
demaged.
[toc] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2022-07-27 13:05 -0700 |
| Message-ID | <874jz2xqw1.fsf@nosuchdomain.example.com> |
| In reply to | #85700 |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> Jivanmukta <jivanmukta@poczta.onet.pl> writes:
>> bool get_next_line(std::string &line);
> ...
>> get_next_line()
>>returns spoilt line.
>
> You complain about get_next_line, yet you only show us its
> declaration, not its implementation. This means that you are
> still missing basics of C++ class implementation. You need to
> learn the fundamentals of C++ /before/ you can begin to edit
> such class implementations.
The fact that the OP didn't show us the implementation of a function
doesn't necessarily imply anything about their knowledge of C++.
We all forget things now and then.
> One might also add that get_next_line returns a bool, so it
> can never return a line.
Right, but it takes a std::string by reference, so it can update its
value. Saying that it "returns" a string is imprecise, but not horribly
so.
[...]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web