i have a string which is giving me problems. when i put it into a textfile, it puts the cursor onto the nextline. i assume because there is a \n at the end of the string, but when i cout the string, the newline character isnt there (well, the console doesnt put the next peice of text on the newline). is there someway i can stop it adding this newline? because its causing my program to crash later on.
lexusdominus 1 Junior Poster in Training
Recommended Answers
Jump to Post…#include <fstream> #include <string> using namespace std; int main() { string word1 = "dog\n\n"; string word2 = "dog\n"; string word3 = "dog"; ofstream out("dog.txt", ios::app|ios::ate); out << word1 << word2 << word3; out.close(); ofstream out2("dog.txt", ios::app|ios::ate); out2 << word1 << word2 << word3; out2.close(); return 0; }
Jump to Postok, the problem im having is that when i put text into my textfile, i first put a "\n" and then the data. it works fine and everything is dandy. but in this occasion, it is putting the "cursor" (i dont care what you call it, the little vertical line …
Jump to Post>> im sure such a powerful language as c can do such a simple task. all i want to do is move the end of the file
I didn't say it couldn't do it. I said that (to the best of my knowledge) there is no STANDARD way of …
Jump to Post>> it is so frustrating.
I hear you. It's in there, somewhere, though. It has to be. Without seeing the file and all the code, I have no idea where, but here's a little test you can use to check things quickly to make sure things are as they …
All 15 Replies
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
lexusdominus 1 Junior Poster in Training
lexusdominus 1 Junior Poster in Training
caut_baia 9 Posting Whiz
lexusdominus 1 Junior Poster in Training
caut_baia 9 Posting Whiz
VernonDozier 2,218 Posting Expert Featured Poster
lexusdominus 1 Junior Poster in Training
lexusdominus 1 Junior Poster in Training
VernonDozier 2,218 Posting Expert Featured Poster
lexusdominus 1 Junior Poster in Training
VernonDozier 2,218 Posting Expert Featured Poster
lexusdominus 1 Junior Poster in Training
VernonDozier 2,218 Posting Expert Featured Poster
lexusdominus 1 Junior Poster in Training
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.