Ask coding questions

← Back to all posts
How to include Text
softwarenginner

I want to include my text file into my code. And if the text it match with the number or letter. I want user to access his own files.

Voters
softwarenginner
Comments
hotnewtop
Giothecoder
Giothecoder

Um. Why not just use an <fstream> object? You can’t just directly place non-code in your code.

Zavexeon

@Giothecoder I think he's trying to turn the contents of a .txt file into a string. It's totally possible.

Giothecoder

@Zavexeon once it hits a certain size though, that’ll be trouble, it will take up so much space, and if you have just a single quotation mark in there and you want to make a string with a #include inside, it’s fed.

Giothecoder

@Giothecoder actually, getline works though. It will read to EOF if you give it a big enough buffer or a character that isn’t in the file.

softwarenginner

@Giothecoder I mean by that is. how Can I include my text file to my code.

Highwayman

@softwarenginner what you should ask yourself is: "does my txt file contain valid code?" If the answer is no, then no. If the answer is yes, then yes.