Sending data from C++ app to Arduino via Serial Port?

wow. Didn't think it would be that complicated, but I guess nothing is easy. Well, here's my c++ code. Probably very amatuerish programming which is why it doesn't work:

C++ program running on host computer:

#include <iostream>
#include <fstream>

int main(int argc, char* argv[])
{
	//open arduino device file (linux)
        std::ofstream arduino;
	arduino.open( "/dev/ttyACM0");

	//write to it
        arduino << "Hello from C++!";
	arduino.close();

	return 0;
}

It's probably missing all that opening port stuff you mentioned. I have no idea how to go about that. Is there a serial library for C++ similar to python? Would it really be necessary? Isn't the device file enough? I thought that was the beauty of linux? You could just write/read to "files".

arduino sketch:

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char buffer[256];

void setup() {
    Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
}

void loop() {

	// send data only when you receive data:
	if (Serial.available() > 0) {

	// read the data
        Serial.readBytes(buffer, 256);
                
	// say what you got:
        lcd.print(buffer);

	}

}

Again, this works fine as long as the serial monitor from the ide is open. I don't print anything to the serial monitor, it just has to be opened. But the string still gets to the lcd.

I had no idea the Arduino resets when the serial port opens. Also, didn't know you had to wait for it to be ready. Again, harder than I thought. I''ll try to study the python examples and see if I could get it to work in C++. Any suggestions appreciated. thanks.