我在VB中编写了一个程序,它将数据导出到一个文本文件中,我希望用C ++中的另一个程序读取该文件,然后将该数据指定为变量。 该程序本质上是一个测验,我在VB中编写的程序是问题制作者,它将所需的所有数据导出到文本文件中。
以下是文本文件:
test question|test A|test B|test C|test D|A|100|0|0|0|Right, I know this. The answer is 100% A. Good luck!|B|100|0|从左到右,我们有问题,答案A,答案B,答案C,答案D,正确答案,百分比1,2,3,4,(用于轮询观众他们认为答案可能是什么)朋友的回答,错误答案(程序在一个点上消除了两个错误的答案,这个答案是剩下的错误答案)和百分比1和2(如果他们消除了2个错误的答案但仍然想要一个民意调查)。
我做了很多谷歌搜索,但没有发现我的下一个问题(也许是因为我使用了错误的关键字,在编程术语时我没有受过太多教育)。 我希望C ++程序做的是读取文件,当它看到“|”时 它知道即将发生的是一个新变量。 我会更好地使用ifstream或其他东西,我怎么告诉程序识别“|” 并使其作为变量读取其中的任何内容?
I've written a program in VB which exports data into a text file, which I want to be read by another program in C++ and then that data be assigned as a variable. The program is essentially a quiz and the program I wrote in VB is question maker that exports all the data required into the text file.
Below is the text file:
test question|test A|test B|test C|test D|A|100|0|0|0|Right, I know this. The answer is 100% A. Good luck!|B|100|0|From left to right we have, the question, AnswerA, AnswerB, AnswerC, AnswerD, the correct answer, percent 1, 2, 3, 4, (for polling an audience of what they think the answer may be) a friend's answer, a wrong answer (the program eliminates two wrong answers at one point, this answer is the remaining wrong answer) and percent 1 and 2 again (in case they eliminate 2 wrong answers but still want a poll).
I did quite a lot of google searching but found nothing to my following question (perhaps due to the fact I used the wrong keywords, I'm not too educated when it comes to programming jargon). What I want the C++ program to do is read the file and when it sees "|" it knows that what is coming is a new variable. Would I be better using ifstream or something else and how would I tell the program to identify the "|" and make it read whatever is in between as a variable?
最满意答案
查看istream::getline 的文档 。 你可以使用| 字符作为分隔符。
Look at the documentation for istream::getline. You can use the | character as a delimiter.
C ++使用ifstream从外部文件变量(C++ Variables from external file using ifstream)我在VB中编写了一个程序,它将数据导出到一个文本文件中,我希望用C ++中的另一个程序读取该文件,然后将该数据指定为变量。 该程序本质上是一个测验,我在VB中编写的程序是问题制作者,它将所需的所有数据导出到文本文件中。
以下是文本文件:
test question|test A|test B|test C|test D|A|100|0|0|0|Right, I know this. The answer is 100% A. Good luck!|B|100|0|从左到右,我们有问题,答案A,答案B,答案C,答案D,正确答案,百分比1,2,3,4,(用于轮询观众他们认为答案可能是什么)朋友的回答,错误答案(程序在一个点上消除了两个错误的答案,这个答案是剩下的错误答案)和百分比1和2(如果他们消除了2个错误的答案但仍然想要一个民意调查)。
我做了很多谷歌搜索,但没有发现我的下一个问题(也许是因为我使用了错误的关键字,在编程术语时我没有受过太多教育)。 我希望C ++程序做的是读取文件,当它看到“|”时 它知道即将发生的是一个新变量。 我会更好地使用ifstream或其他东西,我怎么告诉程序识别“|” 并使其作为变量读取其中的任何内容?
I've written a program in VB which exports data into a text file, which I want to be read by another program in C++ and then that data be assigned as a variable. The program is essentially a quiz and the program I wrote in VB is question maker that exports all the data required into the text file.
Below is the text file:
test question|test A|test B|test C|test D|A|100|0|0|0|Right, I know this. The answer is 100% A. Good luck!|B|100|0|From left to right we have, the question, AnswerA, AnswerB, AnswerC, AnswerD, the correct answer, percent 1, 2, 3, 4, (for polling an audience of what they think the answer may be) a friend's answer, a wrong answer (the program eliminates two wrong answers at one point, this answer is the remaining wrong answer) and percent 1 and 2 again (in case they eliminate 2 wrong answers but still want a poll).
I did quite a lot of google searching but found nothing to my following question (perhaps due to the fact I used the wrong keywords, I'm not too educated when it comes to programming jargon). What I want the C++ program to do is read the file and when it sees "|" it knows that what is coming is a new variable. Would I be better using ifstream or something else and how would I tell the program to identify the "|" and make it read whatever is in between as a variable?
最满意答案
查看istream::getline 的文档 。 你可以使用| 字符作为分隔符。
Look at the documentation for istream::getline. You can use the | character as a delimiter.
发布评论