Hey I am a beginner at C++, and I was wondering how I would make a program that you could input a line of different names and Input them into a Word file.
(my friends website outputs names with | inbetween them and I dont want to take the time to delete and seperate the names, easier to code it maybe :D )
So it would take the line of code example:
Name|Race|Religion|Birthday|Phone Number|Date of Registration
and I know you can put things in and put breaks between them with '.'
but how would i make it assign each segment to a different array number
and then enter into Word and between each array would hit tab to create space inbetween them.
Sorry if I am asking a lot.
I just can't figure it out :P
#include <iostream>
#include <sstream>
#include <string>
#include <vector> // for the vector option
using namespace std;
int main()
{
string sentence, word;
// create a string vector to hold the words
vector<string> sV;
cout << "Enter a sentence: ";
getline(cin, sentence);
// put the sentence into a stream
istringstream instr(sentence);
// the >> operator separates the stream at a whitespace
while (instr >> word)
{
cout << word << endl;
// optionally store each word in a string vector
// could use an array, but a vector is easier
sV.push_back(word);
}
// now let's look at the vector
cout << "You typed " << sV.size() << " words:\n";
for(int k = 0; k < sV.size(); k++)
{
cout << sV[k] << endl;
}
That would require some work, as it can't be done with standard C++. Not trying to be rude, but if you didn't know how to write a program to accept and parse some input into a vector, something like that will be utterly beyond you.