How to copy char array into another in C++

2 Answers

0 votes
#include <iostream>
#include <vector>
#include <algorithm>

int main(void) {
	std::vector<wchar_t> src = {L'a', L'b', L'c', L'd', L'e', L'f', L'g'};
	std::vector<wchar_t> dest(src.size());

	std::copy_n(src.begin(), src.size(), dest.begin());

	for (auto ch : dest) {
		std::wcout << ch << " ";
	}
}



/*
run:

a b c d e f g 

*/

 



answered Aug 15, 2022 by avibootz
0 votes
#include <iostream>
#include <vector>
#include <algorithm>
 
int main(void) {
    std::vector<char> src = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
    std::vector<char> dest(src.size());
 
    std::copy_n(src.begin(), src.size(), dest.begin());
 
    for (auto ch : dest) {
        std::cout << ch << " ";
    }
}
 
 
 
/*
run:
 
a b c d e f g 
 
*/

 



answered Aug 15, 2022 by avibootz

Related questions

1 answer 158 views
1 answer 165 views
165 views asked Aug 15, 2022 by avibootz
1 answer 232 views
1 answer 131 views
2 answers 283 views
1 answer 227 views
2 answers 248 views
...