There is one detailproblem that always occurs when I read text from a file and then putting this text to a multilined richTextBox.
What happens is that the text begins on Row number 2 in the textbox and not on the top(Row 1).
It seems that a linecharacter perheps is added somewhere but I cant see it.
Because when I the save the text from the textBox and then open the textfile again it starts on Row 3 and so on.
I dont know if I do something wrong in the code.

std::string FileText = "C:\\File1.txt";
ifstream ReadFile(FileText .c_str());


std::string Dummy;
std::vector<string> Fill;
int count = 0;

while( getline(ReadFile, Dummy) )
{
	Fill.push_back(Dummy);
	count = count + 1;
}

	
//Now put the elements in vector Fill to textBox			
String^ text;
for( int i = 0; i < count; i++ )
{
	String^ Dummy2 = gcnew String(Fill[i].c_str());
	text += System::Environment::NewLine + Dummy2 ;
	this->richTextBox1->WordWrap = false;
	this->richTextBox1->Text = text ;
}

Recommended Answers

All 5 Replies

This probably won't solve your problem, but ... Do you really need that vector? Why not just combine those two loops?

Perhaps opening and closing the string for the box causes a 'return' to be placed on it each time. Then, when you open the string again, the stream starts at the end of the string, which would cause it to be on the second line, then third, etc. Try accessing the string at the beginning if there is such a parameter.

I think you'd want to have the string and the newline the other way around, i.e.

text += Dummy2 + System::Environment::NewLine;

That is true.. I did actually take the vector away. As you said it wasn´t neccesary.

This probably won't solve your problem, but ... Do you really need that vector? Why not just combine those two loops?

That was the trick, it did put a newline first, I did not notice that.
It solved the problem. Thank you...

I think you'd want to have the string and the newline the other way around, i.e.

text += Dummy2 + System::Environment::NewLine;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.