关于linux编程解决方法
关于linux编程
在Linux下编写程序,要求打开一个文本文件,读入一行内容,将其中的小写转换成为大写,其他不变,文件名作为命令行参数输入!!!拜托啦 下午上课要呢
------解决方案--------------------
~/test> g++ -o toUpper toUpper.cpp
~/test> ./toUpper od.txt
ABADFFAADD
DFDADDDAAF
ASDASDIOSS
在Linux下编写程序,要求打开一个文本文件,读入一行内容,将其中的小写转换成为大写,其他不变,文件名作为命令行参数输入!!!拜托啦 下午上课要呢
------解决方案--------------------
~/test> g++ -o toUpper toUpper.cpp
~/test> ./toUpper od.txt
ABADFFAADD
DFDADDDAAF
ASDASDIOSS
- C/C++ code
#include <iostream> #include <string> #include <fstream> #include<algorithm> using namespace std; int main(int argc, char* argv[]) { if (argc != 2) { cout << "usage: " << argv[0] << "filename" << endl; return 1; } ifstream ifs(argv[1]); if (!ifs) { cout << "Error: to open the file: " << argv[1] << endl; return 1; } string str; while (getline(ifs, str)) { transform(str.begin(),str.end(),str.begin(),::toupper); cout<< str <<endl; } ifs.close(); return 0; }
------解决方案--------------------