Re: vector crash

2024-01-21 Thread zjh via Digitalmars-d-learn
On Sunday, 21 January 2024 at 18:38:42 UTC, atzensepp wrote: What if you add more lines to the file. Does it crash then later? It's a problem with `vectors`. `vector!string` has a problem , I just use 'string []', and it's OK. The `vector` is unstable, possibly because the `later data`

Re: vector crash

2024-01-21 Thread atzensepp via Digitalmars-d-learn
On Sunday, 21 January 2024 at 03:54:35 UTC, zjh wrote: On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: ```d void toV(string a,ref vector!string b){ auto f=File(a,"r"); while(!f.eof()){ string l=strip(f.readln());push(b,l); } Qwk(b); }// ``` There is an issue

Re: vector crash

2024-01-20 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: ```d void toV(string a,ref vector!string b){ auto f=File(a,"r"); while(!f.eof()){ string l=strip(f.readln());push(b,l); } Qwk(b); }// ``` There is an issue with the `vector` here, I don't know why the subsequent

Re: vector crash

2024-01-18 Thread zjh via Digitalmars-d-learn
On Friday, 19 January 2024 at 02:13:08 UTC, zjh wrote: ... `Compile command`: ```d dmd -i cy2.d dparse.lib ``` need libdparse lib.

Re: vector crash

2024-01-18 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: ```d import std.stdio, std.range,std.file; import std.string:strip; import dparse.ast; import dparse.lexer; import dparse.parser : parseModule; import dparse.rollback_allocator : RollbackAllocator; import core.stdcpp.vector; import

Re: vector crash

2024-01-18 Thread Renato via Digitalmars-d-learn
On Thursday, 18 January 2024 at 04:31:52 UTC, zjh wrote: On Thursday, 18 January 2024 at 04:24:18 UTC, zjh wrote: ```d class V : ASTVisitor { Vector!string f=[]; alias visit = ASTVisitor.visit; override void visit(const FunctionDeclaration decl) { writeln('

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 04:24:18 UTC, zjh wrote: ```d class V : ASTVisitor { Vector!string f=[]; alias visit = ASTVisitor.visit; override void visit(const FunctionDeclaration decl) { writeln(' '.repeat(indentLevel * 4), decl.name.text);

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 04:20:12 UTC, zjh wrote: foreach(e;d){ ```d foreach(e;d){//.0 string b=e; string m=readText(b);ff(m,b); } ``` or here `.0`? why crash?

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:53:09 UTC, Steven Schveighoffer wrote: Are you sure this is what you are wanting to do? -Steve ```d void gg(string a){ Vector!string d=[];toV(a,d);//File to Vector print(d);//3,OK foreach(e;d){ string b=e;//.1 string

Re: vector crash

2024-01-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: ```d import dparse.ast; import dparse.lexer; import dparse.parser : parseModule; import dparse.rollback_allocator : RollbackAllocator; import core.stdcpp.vector; import core.stdcpp.string; ... ``` I have no experience with using cpp from

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:11:57 UTC, zjh wrote: ```d string b=d[i];//the 3th:vector.d //`+Object`,crashes! ``` ```d //d[i]==>e string b=e; ``` in the foreach.

Re: vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
On Thursday, 18 January 2024 at 03:07:13 UTC, zjh wrote: Why can `b` still affect `e` here? Isn't `b` copied? here foreach crashes. Starting from the `third one`, it crashes. It's clearly `vector.d`, but the result is`+Object`. ```d string b=d[i];//the 3th:vector.d //`+Object`,crashes! ```

vector crash

2024-01-17 Thread zjh via Digitalmars-d-learn
```d import dparse.ast; import dparse.lexer; import dparse.parser : parseModule; import dparse.rollback_allocator : RollbackAllocator; import core.stdcpp.vector; import core.stdcpp.string; Vector!string d=[];toV(a,d); print(d);//3 foreach(e;d){ string b=d[i]; string