テキストファイルには、次のようになります。テキストファイルから読み込んだ改行文字をC++で保存することはできますか?
this is a test \n to see if it breaks into a new line.
C++は次のようになります。
this is a test \n to see if it breaks into a new line.
I:あなたは出力ファイルに 'test' と書いた場合、それはこのようになります
string test;
ifstream input;
input.open("input.txt");
getline(input, test);
それがファイルに書き込まれるときに '\ n'文字に遭遇したときに改行するようにしてください。 "TEXT.TXT" の
#include <fstream>
using namespace std;
int main() {
fstream file;
file.open("test.txt");
string test = "this is a test \n to see if it breaks into a new line.";
file << test;
file.close();
return 0;
}
結果:触発され
this is a test
to see if it breaks into a new line..
:
'\ n'は、ソースコードの文字列リテラルの中に書かれたときにのみ、「改行」の意味を持ちます。テキストファイルの中(または基本的にはどこか他の場所)には、バックスラッシュの後ろにnが続くだけです。 ) – Thomas
ええと、それを1行に1変数として保存して、2行として書くことができるようにtrynigしていたのですが、入力ファイルに改行を入れるのが最も簡単でした。 – Jay
@Jayがあなたを待っています。あなたはそれらを読んで1つを受け入れるべきです、私は言うでしょう。 – gsamaras